internal void SendMessages(string url, string clusterID)
                {
                    IStanConnection sc = null;

                    sc = CreateConnection(url, clusterID, "synadia-rel-publisher");
                    for (int i = 0; !IsFinished(); i++)
                    {
                        try
                        {
                            sc.Publish("synadia.restest", payload, (obj, args) => { /* NOOP */ });
                            // sync publish for long running stability
                            // sc.Publish("synadia.restest", payload); ;
                        }
                        catch (Exception e)
                        {
                            Log("Publish Exception: " + e.Message);
                            Thread.Sleep(250);
                        }

                        if (i % 500 == 0)
                        {
                            Log("Publisher Sent {0} messages to the streaming server.", i);
                            PrintResourceStats();
                        }
                    }
                    sc?.Close();

                    Log("Publisher is finished.");
                }
Esempio n. 2
0
 public void Stop()
 {
     _cancellationTokenSource.Cancel();
     _subscription.Close();
     _connection.Close();
     _storingData.Close();
 }
                internal void ProcessMsgs(string url, string clusterID)
                {
                    IStanConnection sc = null;

                    try
                    {
                        sc = CreateConnection(url, clusterID, "synadia-rel-sub");

                        var opts = StanSubscriptionOptions.GetDefaultOptions();
                        opts.AckWait     = 60000;
                        opts.ManualAcks  = true;
                        opts.MaxInflight = 32;
                        opts.DurableName = "synadia-restest";

                        sc.Subscribe("synadia.restest", "qg", opts, ProcessMsg);

                        FeV.WaitOne();
                    }
                    catch (Exception e)
                    {
                        Log("Create Subscriber failed: " + e);
                    }
                    finally
                    {
                        sc?.Close();
                    }

                    Log("Subscriber is finished.");
                }
Esempio n. 4
0
 protected void cleanup()
 {
     if (sOpts.DurableName != null && unsubscribe)
     {
         s?.Unsubscribe();
     }
     c?.Close();
 }
Esempio n. 5
0
 private void CloseAndDisposeStan()
 {
     if (stanConnection != null)
     {
         stanConnection.Close();
         stanConnection.Dispose();
     }
 }
Esempio n. 6
0
        public void close()
        {
            if (dicSubscription.Count > 0)
            {
                foreach (var keyPair in dicSubscription)
                {
                    keyPair.Value.Close();
                }
            }

            conn?.Close();
        }
        public Task StopAsync(CancellationToken cancellationToken)
        {
            if (!stoppedValue)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation($"Stopping hosted service \"{nameof(StanMessageReceiverService)}\".");
                }

                try
                {
                    _cancellationTokenSource?.Cancel();
                    if (_tasks != null)
                    {
                        try
                        {
                            Task.WaitAll(_tasks, 5000);
                        }
                        catch (AggregateException)
                        {
                        }
                    }

                    _connection?.Close();
                    _connection?.Dispose();


                    stoppedValue = true;

                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation($"Stopped hosted service \"{nameof(StanMessageReceiverService)}\".");
                    }
                }
                catch (Exception e)
                {
                    if (_logger.IsEnabled(LogLevel.Information))
                    {
                        _logger.LogInformation($"Stopping hosted service \"{nameof(StanMessageReceiverService)}\" throws exception. {e.Message}");
                    }
                    throw e;
                }
            }

            return(Task.CompletedTask);
        }
Esempio n. 8
0
 public void Stop()
 {
     _repo.Close();
     _natsConnection.Close();
     _stanConnection.Close();
 }
Esempio n. 9
0
 public void Stop()
 {
     _cancellationTokenSource.Cancel();
     _connection.Close();
 }
Esempio n. 10
0
 public void CloseConnection()
 {
     _stanConnection.Close();
 }
Esempio n. 11
0
 public void Dispose()
 {
     _connection.Close();
     _connection?.Dispose();
 }
Esempio n. 12
0
 public void Stop()
 {
     _stanConnection.Close();
 }