Example #1
0
        /// <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");
            }
        }
Example #2
0
 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");
            }
        }
Example #5
0
 protected void Application_End()
 {
     if (_bus != null)
     {
         _bus.Dispose();
     }
 }
Example #6
0
 public void Dispose()
 {
     _advancedBus.QueueDelete(_systemXQueue);
     _advancedBus.QueueDelete(_transMedQueue);
     _advancedBus.ExchangeDelete(_transMedExchange);
     _advancedBus.ExchangeDelete(_systemXExchange);
     _advancedBus.Dispose();
 }
Example #7
0
 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);
 }
Example #9
0
 public void Close()
 {
     if (_bus != null)
     {
         _bus.Dispose();
         _bus = null;
     }
 }
Example #10
0
        /// <inheritdoc />
        public void Disconnect()
        {
            if (_isDisposed)
            {
                return;
            }

            _consumer?.Dispose();
            _advancedBus?.Dispose();
        }
Example #11
0
        public Task StopAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Stopping...");

            _telegramBotClient.StopReceiving();
            _bus?.Dispose();

            _logger.LogInformation("Stopped");

            return(Task.CompletedTask);
        }
Example #12
0
        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);
        }
Example #13
0
        /// <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();
        }
Example #14
0
        /// <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");
            }
        }
Example #15
0
        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;
            }
        }
Example #16
0
 public void TearDown()
 {
     _advancedBus.Dispose();
     _notificationEngineMqServer.Disconnect();
 }
Example #17
0
 public void TearDown()
 {
     advancedBus.Dispose();
 }
Example #18
0
        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;
            }
        }
Example #19
0
 public virtual void Dispose()
 {
     advancedBus.Dispose();
 }
Example #20
0
 public void Dispose()
 {
     advancedBus.Dispose();
 }
Example #21
0
 public static void AfterTestRun()
 {
     Bus.Dispose();
 }
Example #22
0
 public void TearDown()
 {
     bus.Dispose();
 }
Example #23
0
 /// <inheritdoc/>
 public void Dispose()
 {
     bus.Dispose();
 }
 public void Dispose()
 {
     _bus?.Dispose();
 }
Example #25
0
 public void Stop()
 {
     _client?.Dispose();
 }
 /// <summary>
 /// Stop MQ Server
 /// </summary>
 public void Disconnect()
 {
     _easyNetQBus.Dispose();
     _rabbitMqTickConnection.Close();
     //_rabbitMqBarConnection.Close();
 }
Example #27
0
 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();
 }