/// <summary> /// Disconnects MQ Server and terminate necessary resources /// </summary> public void Disconnect() { try { // Dispose Rabbit Bus if (_rabbitBus != null) { _rabbitBus.Dispose(); _rabbitMqChannel.Close(); _rabbitMqConnection.Close(); if (Logger.IsInfoEnabled) { Logger.Info("Advanced Bus disposed off.", _type.FullName, "Disconnect"); } } // Stop Consumer if (_executionMessageConsumerCancellationToken != null) { _executionMessageConsumerCancellationToken.Cancel(); } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "Disconnect"); } }
protected override void Dispose(bool disposing) { if (disposing) { advancedBus.Dispose(); } }
public void TearDown() { if (advancedBus != null) { advancedBus.Dispose(); } }
/// <summary> /// Closes communication channels /// </summary> public void Disconnect() { try { // Dispose Rabbit Bus if (_advancedBus != null) { _advancedBus.Dispose(); _rabbitMqChannel.Close(); _rabbitMqConnection.Close(); _advancedBus.Connected -= OnBusConnected; _advancedBus.Connected -= OnBusDisconnected; if (Logger.IsInfoEnabled) { Logger.Info("Advanced Bus disposed off.", _type.FullName, "Disconnect"); } } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "Disconnect"); } }
protected void Application_End() { if (_bus != null) { _bus.Dispose(); } }
public void Dispose() { _advancedBus.QueueDelete(_systemXQueue); _advancedBus.QueueDelete(_transMedQueue); _advancedBus.ExchangeDelete(_transMedExchange); _advancedBus.ExchangeDelete(_systemXExchange); _advancedBus.Dispose(); }
public void Dispose() { if (advancedBus != null) { advancedBus.Dispose(); } GC.SuppressFinalize(this); }
protected override void OnClosed(EventArgs e) { if (_bus != null) { _bus.Dispose(); } base.OnClosed(e); }
public void Close() { if (_bus != null) { _bus.Dispose(); _bus = null; } }
/// <inheritdoc /> public void Disconnect() { if (_isDisposed) { return; } _consumer?.Dispose(); _advancedBus?.Dispose(); }
public Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Stopping..."); _telegramBotClient.StopReceiving(); _bus?.Dispose(); _logger.LogInformation("Stopped"); return(Task.CompletedTask); }
private static int RunService() { var builder = new ContainerBuilder(); builder.RegisterAssemblyModules(typeof(Program).Assembly); var exitCode = HostFactory.Run( x => { var container = builder.Build(); messageBus = container.Resolve <IAdvancedBus>(); x.UseAutofacContainer(container); x.UseSerilog(); var httpConfig = container.Resolve <HttpConfiguration>(); httpConfig.DependencyResolver = new AutofacWebApiDependencyResolver(container); var serviceConfiguration = container.Resolve <ITopshelfConfiguration>(); x.SetServiceName(serviceConfiguration.ServiceName); x.SetDescription(serviceConfiguration.ServiceDescription); x.SetDisplayName(serviceConfiguration.ServiceDisplayName); x.Service <ServiceRunner>( s => { s.ConstructUsingAutofacContainer(); s.WhenStarted(i => i.Start()); s.WhenStopped(i => i.Stop()); }); }); if (exitCode == TopshelfExitCode.Ok && messageBus != null) { try { messageBus.Dispose(); } catch (Exception ex) { Log.Error(ex, "An error occurred while shutting down the service."); exitCode = TopshelfExitCode.AbnormalExit; } } return((int)exitCode); }
/// <summary> /// Stop MQ Server /// </summary> public void Disconnect() { _tickconsumer.OnCancel(); _tokenSource.Cancel(); //_dataConsumerTask.Dispose(); //_barTask.Dispose(); _easyNetQBus.Dispose(); _easyNetQBus = null; _rabbitMqTickChannel.QueueDelete("simulated.tickdata.queue"); _rabbitMqTickChannel.Close(); _rabbitMqTickConnection.Close(); _rabbitMqTickBus = null; //_rabbitMqBarChannel.Close(); //_rabbitMqBarConnection.Close(); }
/// <summary> /// Disconnects the running intance of the Rabbit Hutch /// </summary> public void Disconnect() { try { // Dispose Rabbit Bus if (_rabbitBus != null) { _rabbitBus.Dispose(); if (Logger.IsInfoEnabled) { Logger.Info("Advanced Bus disposed off.", _type.FullName, "Disconnect"); } } } catch (Exception exception) { Logger.Error(exception, _type.FullName, "Disconnect"); } }
private static void ConsumeMessage(IAdvancedBus advancedBus) { try { var queueName = "ZNJB.Order"; var routingKey = "ZNJB.*"; var queue = advancedBus.QueueDeclare(queueName); var count = advancedBus.MessageCount(queue); if (count <= 0) { Console.WriteLine("count=0"); advancedBus.Dispose(); return; } var exchange = advancedBus.ExchangeDeclare("ZNJB.exchange", ExchangeType.Topic); var binding = advancedBus.Bind(exchange, queue, routingKey); for (var message = 1; message <= NumberOfConsume; message++) { var Client = new ConsumerClient(); lock (Clients) { Clients.Add(Client); } Task.Run(() => { Client.StartClient(advancedBus, queue); lock (Clients) { Clients.Remove(Client); Monitor.PulseAll(Clients); } }); while (Clients.Count >= 500) { lock (Clients) { Monitor.Wait(Clients, 5000); } } } while (Clients.Count > 0) { lock (Clients) { Monitor.Wait(Clients, 5000); } } lock (LockingObject) { Monitor.PulseAll(LockingObject); } } catch (Exception ex) { throw ex; } }
public void TearDown() { _advancedBus.Dispose(); _notificationEngineMqServer.Disconnect(); }
public void TearDown() { advancedBus.Dispose(); }
private static void GetMessage(IAdvancedBus advancedBus) { try { var sw = new Stopwatch(); sw.Start(); var queueName = "ZNJB.Order"; var routingKey = "ZNJB.*"; var queue = advancedBus.QueueDeclare(queueName); var count = advancedBus.MessageCount(queue); if (count <= 0) { Console.WriteLine("count=0"); advancedBus.Dispose(); return; } var exchange = advancedBus.ExchangeDeclare("ZNJB.exchange", ExchangeType.Topic); var binding = advancedBus.Bind(exchange, queue, routingKey); //advancedBus.Consume(queue, x => x.Add<TraceableCodeSub>((message, info) => { HandleMessage(message); })) // .SafeDispose(); //{"Properties":{"ContentType":null,"ContentEncoding":null,"Headers":{},"DeliveryMode":0,"Priority":0,"CorrelationId":null,"ReplyTo":"my_reply_queue","Expiration":null,"MessageId":null,"Timestamp":0,"Type":null,"UserId":null,"AppId":"e2d1f4209ef5401f992313ba37fcae6c","ClusterId":null,"ContentTypePresent":false,"ContentEncodingPresent":false,"HeadersPresent":true,"DeliveryModePresent":false,"PriorityPresent":false,"CorrelationIdPresent":false,"ReplyToPresent":true,"ExpirationPresent":false,"MessageIdPresent":false,"TimestampPresent":false,"TypePresent":false,"UserIdPresent":false,"AppIdPresent":true,"ClusterIdPresent":false}, //"MessageType":"ZNJB.Entitys.TraceableCodeSub, ZNJB.Entitys, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", //"Body":{ //"Sid":"e2d1f4209ef5401f992313ba37fcae6c", //"Mid":"0cf59b07c5ae4cee8a8f9bdc0ccae4d4", //"OrderNo":"ZNJB37270155702","CodeType":1, //"TraceableCode":"11000301170008103075629506", //"CreateTime":"2017-03-07T16:49:15.7303122+08:00", //"OrgID":"edd45816-cda2-4f9f-9005-af39de8656a4"}} advancedBus.Consume(queue, (body, properties, info) => { Task t = Task.Factory.StartNew(() => { var message = System.Text.Encoding.UTF8.GetString(body); var success = InsertToDb(message); }); t.Wait(); }); advancedBus.Consume(queue, (body, properties, info) => Task.Factory.StartNew(() => { //Console.WriteLine("ConsumerTag: {0}", info.ConsumerTag); //Console.WriteLine("DeliverTag: {0}", info.DeliverTag); //Console.WriteLine("Redelivered: {0}", info.Redelivered); //Console.WriteLine("Exchange: {0}", info.Exchange); //Console.WriteLine("RoutingKey: {0}", info.RoutingKey); var message = System.Text.Encoding.UTF8.GetString(body); InsertToDb(message); }) .ContinueWith((o) => Task.Factory.StartNew(() => { if (o.Status == TaskStatus.Faulted) { Console.WriteLine("Faulted"); } })) ); sw.Stop(); //Console.WriteLine("客户端接收耗时:" + sw.ElapsedMilliseconds + "毫秒"); //advancedBus.Dispose(); //Console.ReadKey(); } catch (Exception ex) { throw ex; } }
public virtual void Dispose() { advancedBus.Dispose(); }
public void Dispose() { advancedBus.Dispose(); }
public static void AfterTestRun() { Bus.Dispose(); }
public void TearDown() { bus.Dispose(); }
/// <inheritdoc/> public void Dispose() { bus.Dispose(); }
public void Dispose() { _bus?.Dispose(); }
public void Stop() { _client?.Dispose(); }
/// <summary> /// Stop MQ Server /// </summary> public void Disconnect() { _easyNetQBus.Dispose(); _rabbitMqTickConnection.Close(); //_rabbitMqBarConnection.Close(); }
public static void AfterTestRun() { consumer.Dispose(); Bus.Dispose(); }
/// <summary> /// Stop MQ Server /// </summary> public void Disconnect() { _easyNetQBus.Dispose(); _easyNetQBus = null; }
public override void Dispose() { _bus.Dispose(); base.Dispose(); }