Esempio n. 1
0
        private void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (this._disposed)
            {
                return;
            }

            this._logger.LogWarning(message: "A RabbitMQ connection throw exception. Trying to re-connect...");

            this.TryConnect();
        }
Esempio n. 2
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            Console.WriteLine("rabbitmq connection threw exception, reconnecting");

            TryConnect();
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (this._disposed)
            {
                return;
            }

            // LogHelperNLog.Info("A RabbitMQ connection throw exception. Trying to re-connect...");

            this.TryConnect();
        }
Esempio n. 4
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            Console.WriteLine("一个RabbitMQ连接抛出异常。在贯通……");

            TryConnect();
        }
Esempio n. 5
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs reason)
        {
            if (_disposed)
            {
                return;
            }

            _logger.LogError("RabbitMQ connection is throw because {@reason}. Trying to re-connect...", reason);

            this.PersistentConnect();
        }
Esempio n. 6
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            _logger.Warn("OnCallbackException", "DefaultRabbitMQPersistentConnection", "A RabbitMQ connection throw exception. Trying to re-connect...");

            TryConnect();
        }
Esempio n. 7
0
        private void OnCallbackException(object sender, CallbackExceptionEventArgs args)
        {
            if (_disposed)
            {
                return;
            }

            logger.LogWarning("RabbitMQ Connect is callback exception, now reconnect...");

            TryConnect();
        }
        protected virtual void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (disposed)
            {
                return;
            }

            logger.LogDebug("A RabbitMQ connection throw exception. Trying to re-connect...");

            TryConnect();
        }
Esempio n. 9
0
        private void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            _logger.LogWarning("A conexão com o RabbitMq lançou uma excessão. Tente conectar novamente...");

            TryConnect();
        }
Esempio n. 10
0
        private void OnCallbackException(object sender, CallbackExceptionEventArgs args)
        {
            if (_disposed)
            {
                return;
            }

            _logger.LogWarning($"Uma conexão RabbitMQ lançou uma exceção. Detalhe: {args.Detail} + Exceção: {args.Exception.Message}. Trying to re-connect...");

            TryConnect();
        }
Esempio n. 11
0
        private void ConnectionCallbackExceptionHandler(object sender, CallbackExceptionEventArgs eventArgs)
        {
            if (eventArgs is null)
            {
                return;
            }

            //logger.LogError(new EventId(), eventArgs.Exception, eventArgs.Exception.Message, eventArgs);

            throw eventArgs.Exception;
        }
Esempio n. 12
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            Console.WriteLine("A RabbitMQ connection throw exception. Trying to re-connect...");

            TryConnect();
        }
Esempio n. 13
0
        private void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_dispose)
            {
                return;
            }

            _logger.LogWarning("");

            TryConnect();
        }
Esempio n. 14
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            _logger.LogWarning("Uma conexão RabbitMQ lança exceção. Tentando reconectar ...");

            TryConnect();
        }
Esempio n. 15
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            if (_disposed)
            {
                return;
            }

            _logger.LogWarning("A RabbitMQ connection throw exception. Trying to re-connect...");

            TryConnect();
        }
        protected async Task RecoverQueues()
        {
            foreach (KeyValuePair <string, RecordedQueue> pair in m_recordedQueues)
            {
                string        oldName = pair.Key;
                RecordedQueue rq      = pair.Value;

                try
                {
                    await rq.Recover();

                    string newName = rq.Name;

                    // Make sure server-named queues are re-added with
                    // their new names.
                    // We only remove old name after we've updated the bindings and consumers,
                    // plus only for server-named queues, both to make sure we don't lose
                    // anything to recover. MK.
                    PropagateQueueNameChangeToBindings(oldName, newName);
                    PropagateQueueNameChangeToConsumers(oldName, newName);
                    // see rabbitmq/rabbitmq-dotnet-client#43
                    if (rq.IsServerNamed)
                    {
                        DeleteRecordedQueue(oldName);
                    }
                    RecordQueue(newName, rq);

                    if (m_queueNameChange != null)
                    {
                        foreach (AsyncEventHandler <QueueNameChangedAfterRecoveryEventArgs> h in m_queueNameChange.GetInvocationList())
                        {
                            try
                            {
                                var eventArgs = new QueueNameChangedAfterRecoveryEventArgs(oldName, newName);
                                await h(this, eventArgs);
                            }
                            catch (Exception e)
                            {
                                var args = new CallbackExceptionEventArgs(e);
                                args.Detail["context"] = "OnQueueRecovery";
                                await m_delegate.OnCallbackException(args);
                            }
                        }
                    }
                }
                catch (Exception cause)
                {
                    string s = String.Format("Caught an exception while recovering queue {0}: {1}",
                                             oldName, cause.Message);
                    HandleTopologyRecoveryException(new TopologyRecoveryException(s, cause));
                }
            }
        }
Esempio n. 17
0
 private void OnCallbackException(object sender, CallbackExceptionEventArgs e)
 {
     if (disposed)
     {
         return;
     }
     Console.WriteLine("Connection has thrown an exception. Exception Details");
     Console.WriteLine($"{e.Exception}");
     Console.WriteLine("Attempting to reconnect");
     Console.WriteLine();
     TryConnect();
 }
        private void RecoverConsumers()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            Dictionary <string, RecordedConsumer> recordedConsumersCopy;

            lock (_recordedConsumers)
            {
                recordedConsumersCopy = new Dictionary <string, RecordedConsumer>(_recordedConsumers);
            }

            foreach (KeyValuePair <string, RecordedConsumer> pair in recordedConsumersCopy)
            {
                string           tag  = pair.Key;
                RecordedConsumer cons = pair.Value;

                try
                {
                    string newTag = cons.Recover();
                    lock (_recordedConsumers)
                    {
                        // make sure server-generated tags are re-added
                        _recordedConsumers.Remove(tag);
                        _recordedConsumers.Add(newTag, cons);
                    }

                    foreach (EventHandler <ConsumerTagChangedAfterRecoveryEventArgs> h in ConsumerTagChangeAfterRecovery?.GetInvocationList() ?? Array.Empty <Delegate>())
                    {
                        try
                        {
                            var eventArgs = new ConsumerTagChangedAfterRecoveryEventArgs(tag, newTag);
                            h(this, eventArgs);
                        }
                        catch (Exception e)
                        {
                            var args = new CallbackExceptionEventArgs(e);
                            args.Detail["context"] = "OnConsumerRecovery";
                            _delegate.OnCallbackException(args);
                        }
                    }
                }
                catch (Exception cause)
                {
                    string s = string.Format("Caught an exception while recovering consumer {0} on queue {1}: {2}",
                                             tag, cons.Queue, cause.Message);
                    HandleTopologyRecoveryException(new TopologyRecoveryException(s, cause));
                }
            }
        }
Esempio n. 19
0
        protected void RecoverQueues()
        {
            lock (m_recordedQueues)
            {
                var rqs = new Dictionary <string, RecordedQueue>(m_recordedQueues);
                foreach (KeyValuePair <string, RecordedQueue> pair in rqs)
                {
                    string        oldName = pair.Key;
                    RecordedQueue rq      = pair.Value;

                    try
                    {
                        rq.Recover();
                        string newName = rq.Name;

                        // make sure server-named queues are re-added with
                        // their new names. MK.

                        DeleteRecordedQueue(oldName);
                        RecordQueue(newName, rq);
                        PropagateQueueNameChangeToBindings(oldName, newName);
                        PropagateQueueNameChangeToConsumers(oldName, newName);

                        if (m_queueNameChange != null)
                        {
                            foreach (EventHandler <QueueNameChangedAfterRecoveryEventArgs> h in m_queueNameChange.GetInvocationList())
                            {
                                try
                                {
                                    var eventArgs = new QueueNameChangedAfterRecoveryEventArgs(oldName, newName);
                                    h(this, eventArgs);
                                }
                                catch (Exception e)
                                {
                                    var args = new CallbackExceptionEventArgs(e);
                                    args.Detail["context"] = "OnQueueRecovery";
                                    m_delegate.OnCallbackException(args);
                                }
                            }
                        }
                    }
                    catch (Exception cause)
                    {
                        string s = String.Format("Caught an exception while recovering queue {0}: {1}",
                                                 oldName, cause.Message);
                        HandleTopologyRecoveryException(new TopologyRecoveryException(s, cause));
                    }
                }
            }
        }
Esempio n. 20
0
        void OnCallbackException(object sender, CallbackExceptionEventArgs e)
        {
            logger.Info("Se inicia la ejecución del event handler OnCallbackException");
            logger.Debug("Argumentos del event handler OnCallbackException: sender - {}, eventArgs - {}",
                         sender, e);

            if (_disposed)
            {
                logger.Trace("La instancia ha sido dispuesta, se finaliza la ejecución el event handler");
                return;
            }

            logger.Warn("La conexión al Message Broker ha lanzado una excepción, intentando conectar");
            TryConnect();
        }
Esempio n. 21
0
 protected override async Task Execute(ModelBase model, IBasicConsumer consumer)
 {
     try
     {
         await consumer.HandleModelShutdown(model, reason).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         var details = new Dictionary <string, object>()
         {
             { "consumer", consumer },
             { "context", "HandleModelShutdown" }
         };
         await model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
     }
 }
 protected override async Task Execute(ModelBase model, IAsyncBasicConsumer consumer)
 {
     try
     {
         await consumer.HandleBasicCancelOk(_consumerTag).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         var details = new Dictionary <string, object>()
         {
             { "consumer", consumer },
             { "context", "HandleBasicCancelOk" }
         };
         model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
     }
 }
 private void RunRecoveryEventHandlers()
 {
     foreach (EventHandler <EventArgs> reh in Recovery?.GetInvocationList() ?? Array.Empty <Delegate>())
     {
         try
         {
             reh(this, EventArgs.Empty);
         }
         catch (Exception e)
         {
             var args = new CallbackExceptionEventArgs(e);
             args.Detail["context"] = "OnModelRecovery";
             _delegate.OnCallbackException(args);
         }
     }
 }
Esempio n. 24
0
        protected override async Task ProcessChannelAsync()
        {
            while (await _reader.WaitToReadAsync().ConfigureAwait(false))
            {
                while (_reader.TryRead(out var work))
                {
                    try
                    {
                        var consumer    = work.Consumer;
                        var consumerTag = work.ConsumerTag;
                        switch (work.WorkType)
                        {
                        case WorkType.Deliver:
                            consumer.HandleBasicDeliver(consumerTag, work.DeliveryTag, work.Redelivered, work.Exchange, work.RoutingKey, work.BasicProperties, work.Body);
                            break;

                        case WorkType.Cancel:
                            consumer.HandleBasicCancel(consumerTag);
                            break;

                        case WorkType.CancelOk:
                            consumer.HandleBasicCancelOk(consumerTag);
                            break;

                        case WorkType.ConsumeOk:
                            consumer.HandleBasicConsumeOk(consumerTag);
                            break;

                        case WorkType.Shutdown:
                            consumer.HandleModelShutdown(_model, work.Reason);
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        _model.OnCallbackException(CallbackExceptionEventArgs.Build(e, work.WorkType.ToString(), work.Consumer));
                    }
                    finally
                    {
                        if (work.RentedArray != null)
                        {
                            ArrayPool <byte> .Shared.Return(work.RentedArray);
                        }
                    }
                }
            }
        }
Esempio n. 25
0
 public void HandleModelShutdown(IBasicConsumer consumer, ShutdownEventArgs reason)
 {
     // the only case where we ignore the shutdown flag.
     try
     {
         consumer.HandleModelShutdown(model, reason);
     }
     catch (Exception e)
     {
         var details = new Dictionary <string, object>()
         {
             { "consumer", consumer },
             { "context", "HandleModelShutdown" }
         };
         model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
     }
 }
Esempio n. 26
0
        /// <summary>
        /// 消费回调以后的异常函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="ea"></param>
        private void OnConsumerMessageException(object sender, CallbackExceptionEventArgs ea)
        {
            consumerchannel.Close();
            consumerchannel = null;
            var mres = new ManualResetEventSlim(false);

            while (!mres.Wait(3000))
            {
                try
                {
                    if (!rabbitMQPersistentConnection.IsConnected)
                    {
                        rabbitMQPersistentConnection.TryConnect();
                    }

                    consumerchannel = rabbitMQPersistentConnection.CreateModel();

                    consumerchannel.ExchangeDeclare("order", "direct", true, false);
                    consumerchannel.QueueDeclare("order", true, false, false);
                    consumerchannel.QueueBind("order", "order", "order");

                    var retryArgs = new Dictionary <string, object>
                    {
                        { "x-dead-letter-exchange", "order" },
                        { "x-dead-letter-routing-key", "order" }
                    };

                    consumerchannel.ExchangeDeclare("order" + ".retry", "direct", true, false);
                    consumerchannel.QueueDeclare("order" + ".retry", true, false, false, retryArgs);
                    consumerchannel.QueueBind("order" + ".retry", "order" + ".retry", "order" + ".retry");


                    var consumer = new EventingBasicConsumer(consumerchannel);

                    consumer.Received += OnConsumerMessage;
                    consumerchannel.BasicConsume("order", false, consumer);
                    consumerchannel.CallbackException += OnConsumerMessageException;

                    mres.Set();
                }
                catch (Exception ex)
                {
                    throw new Exception("rabbitMQ宕机了", ex);
                }
            }
        }
        protected void RecoverConsumers()
        {
            var dict = new Dictionary <string, RecordedConsumer>(m_recordedConsumers);

            foreach (KeyValuePair <string, RecordedConsumer> pair in dict)
            {
                string           tag  = pair.Key;
                RecordedConsumer cons = pair.Value;

                try
                {
                    string newTag = cons.Recover();
                    lock (m_recordedConsumers)
                    {
                        // make sure server-generated tags are re-added
                        m_recordedConsumers.Remove(tag);
                        m_recordedConsumers.Add(newTag, cons);
                    }

                    if (m_consumerTagChange != null)
                    {
                        foreach (EventHandler <ConsumerTagChangedAfterRecoveryEventArgs> h in m_consumerTagChange.GetInvocationList())
                        {
                            try
                            {
                                var eventArgs = new ConsumerTagChangedAfterRecoveryEventArgs(tag, newTag);
                                h(this, eventArgs);
                            }
                            catch (Exception e)
                            {
                                var args = new CallbackExceptionEventArgs(e);
                                args.Detail["context"] = "OnConsumerRecovery";
                                m_delegate.OnCallbackException(args);
                            }
                        }
                    }
                }
                catch (Exception cause)
                {
                    string s = String.Format("Caught an exception while recovering consumer {0} on queue {1}: {2}",
                                             tag, cons.Queue, cause.Message);
                    HandleTopologyRecoveryException(new TopologyRecoveryException(s, cause));
                }
            }
        }
        ///<summary>Broadcasts notification of the final shutdown of the connection.</summary>
        public void OnShutdown()
        {
            EventHandler <ShutdownEventArgs> handler;
            ShutdownEventArgs reason;

            lock (m_eventLock)
            {
                handler = m_connectionShutdown;
                reason  = m_closeReason;
                m_connectionShutdown = null;
            }
            if (handler != null)
            {
                foreach (EventHandler <ShutdownEventArgs> h in handler.GetInvocationList())
                {
                    try
                    {
                        h(this, reason);
                    }
                    catch (Exception e)
                    {
                        OnCallbackException(CallbackExceptionEventArgs.Build(e,
                                                                             new Dictionary <string, object>
                        {
                            { "context", "OnShutdown" }
                        }));
                    }
                }
            }
#if NETFX_CORE
#pragma warning disable 0168
            try
            {
                Windows.UI.Xaml.Application.Current.Suspending -= this.HandleApplicationSuspend;
            }
            catch (Exception ex)
            {
                // If called from a desktop app (i.e. unit tests), then there is no current application
            }
#pragma warning restore 0168
#else
            AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload;
#endif
        }
Esempio n. 29
0
 public void HandleBasicCancelOk(IBasicConsumer consumer, string consumerTag)
 {
     UnlessShuttingDown(() =>
     {
         try
         {
             consumer.HandleBasicCancelOk(consumerTag);
         }
         catch (Exception e)
         {
             var details = new Dictionary <string, object>()
             {
                 { "consumer", consumer },
                 { "context", "HandleBasicCancelOk" }
             };
             model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
         }
     });
 }
        protected bool RecoverConnectionDelegate()
        {
            while (!ManuallyClosed)
            {
                try
                {
                    var fh = endpoints.SelectOne(m_factory.CreateFrameHandler);
                    m_delegate = new Connection(m_factory, false, fh, this.ClientProvidedName);
                    return(true);
                }
                catch (Exception e)
                {
                    ESLog.Error("Connection recovery exception.", e);
                    // Trigger recovery error events
                    var handler = m_connectionRecoveryError;
                    if (handler != null)
                    {
                        var args = new ConnectionRecoveryErrorEventArgs(e);
                        foreach (EventHandler <ConnectionRecoveryErrorEventArgs> h in handler.GetInvocationList())
                        {
                            try
                            {
                                h(this, args);
                            }
                            catch (Exception ex)
                            {
                                var a = new CallbackExceptionEventArgs(ex);
                                a.Detail["context"] = "OnConnectionRecoveryError";
                                m_delegate.OnCallbackException(a);
                            }
                        }
                    }

#if NETFX_CORE
                    System.Threading.Tasks.Task.Delay(m_factory.NetworkRecoveryInterval).Wait();
#else
                    Thread.Sleep(m_factory.NetworkRecoveryInterval);
#endif
                }
            }

            return(false);
        }