示例#1
0
 /// <summary>
 /// 回调异常
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Connection_CallbackException(object sender, RabbitMQ.Client.Events.CallbackExceptionEventArgs e)
 {
     IsConnTryConn();
 }
        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;
        }
 public virtual void OnFlowControl(FlowControlEventArgs args)
 {
     FlowControlEventHandler handler;
     lock (m_eventLock)
     {
         handler = m_flowControl;
     }
     if (handler != null)
     {
         foreach (FlowControlEventHandler h in handler.GetInvocationList())
         {
             try
             {
                 h(this, args);
             }
             catch (Exception e)
             {
                 CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
                 exnArgs.Detail["context"] = "OnFlowControl";
                 OnCallbackException(exnArgs);
             }
         }
     }
 }
        public void HandleBasicDeliver(string consumerTag,
                                       ulong deliveryTag,
                                       bool redelivered,
                                       string exchange,
                                       string routingKey,
                                       IBasicProperties basicProperties,
                                       byte[] body)
        {
            IBasicConsumer consumer;
            lock (m_consumers)
            {
                consumer = (IBasicConsumer)m_consumers[consumerTag];
            }
            if (consumer == null)
            {
                if (DefaultConsumer == null) {
                    throw new InvalidOperationException("Unsolicited delivery -" +
                                                        " see IModel.DefaultConsumer to handle this" +
                                                        " case.");
                }
                else {
                    consumer = DefaultConsumer;
                }
            }

            try {
                consumer.HandleBasicDeliver(consumerTag,
                                            deliveryTag,
                                            redelivered,
                                            exchange,
                                            routingKey,
                                            basicProperties,
                                            body);
            } catch (Exception e) {
                CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                args.Detail["consumer"] = consumer;
                args.Detail["context"] = "HandleBasicDeliver";
                OnCallbackException(args);
            }
        }
        public void HandleBasicCancelOk(string consumerTag)
        {
            BasicConsumerRpcContinuation k =
                (BasicConsumerRpcContinuation)m_continuationQueue.Next();

            Trace.Assert(k.m_consumerTag == consumerTag, string.Format(
                                                                       "Consumer tag mismatch during cancel: {0} != {1}",
                                                                       k.m_consumerTag,
                                                                       consumerTag
                                                                       ));

            lock (m_consumers)
            {
                k.m_consumer = (IBasicConsumer)m_consumers[consumerTag];
                m_consumers.Remove(consumerTag);
            }
            try {
                k.m_consumer.HandleBasicCancelOk(consumerTag);
            } catch (Exception e) {
                // FIXME: should we propagate the exception to the
                // caller of BasicCancel?
                CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                args.Detail["consumer"] = k.m_consumer;
                args.Detail["context"] = "HandleBasicCancelOk";
                OnCallbackException(args);
            }
            k.HandleCommand(null); // release the continuation.
        }
        public virtual void OnBasicAck(BasicAckEventArgs args)
        {
            BasicAckEventHandler handler;
            lock (m_eventLock)
            {
                handler = m_basicAck;
            }
            if (handler != null)
            {
                foreach (BasicAckEventHandler h in handler.GetInvocationList()) {
                    try {
                        h(this, args);
                    } catch (Exception e) {
                        CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
                        exnArgs.Detail["context"] = "OnBasicAck";
                        OnCallbackException(exnArgs);
                    }
                }
            }

            handleAckNack(args.DeliveryTag, args.Multiple, false);
        }
示例#7
0
 private void ThrowingModelOnCallbackException(object sender, CallbackExceptionEventArgs e)
 {
     log.Debug("Throwing exception in model callback exception handler");
     throw new Exception();
 }
 ///<summary>Broadcasts notification of the final shutdown of the connection.</summary>
 public void OnShutdown()
 {
     ConnectionShutdownEventHandler handler;
     ShutdownEventArgs reason;
     lock (m_eventLock)
     {
         handler = m_connectionShutdown;
         reason = m_closeReason;
         m_connectionShutdown = null;
     }
     if (handler != null)
     {
         foreach (ConnectionShutdownEventHandler h in handler.GetInvocationList()) {
             try {
                 h(this, reason);
             } catch (Exception e) {
                 CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                 args.Detail["context"] = "OnShutdown";
                 OnCallbackException(args);
             }
         }
     }
     AppDomain.CurrentDomain.DomainUnload -= HandleDomainUnload;
 }
 public void OnConnectionUnblocked()
 {
       ConnectionUnblockedEventHandler handler;
       lock (m_eventLock)
       {
           handler = m_connectionUnblocked;
       }
       if (handler != null)
       {
           foreach (ConnectionUnblockedEventHandler h in handler.GetInvocationList()) {
               try {
                   h(this);
               } catch (Exception e) {
                   CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                   args.Detail["context"] = "OnConnectionUnblocked";
                   OnCallbackException(args);
               }
           }
       }
 }
示例#10
0
 private void ThrowingConnectionCallbackException(object sender, CallbackExceptionEventArgs e)
 {
     log.Debug("Throwing exception in connection callback exception handler");
     throw new Exception();
 }
示例#11
0
 private void CallbackExceptionHandler(object sender, CallbackExceptionEventArgs e)
 {
     this.CallbackException?.Invoke(sender, e);
 }
 private void OnCallbackException(object sender, CallbackExceptionEventArgs e)
 {
     Log.Error(e.Exception, "Callback exception on RabbitMQ.Client");
 }
示例#13
0
 private void ModelOnCallbackException(object sender, CallbackExceptionEventArgs e)
 {
     _logger.Error($"Callback exception: {e.Exception}");
 }
        protected void RecoverConsumers()
        {
            foreach (KeyValuePair<string, RecordedConsumer> pair in m_recordedConsumers)
            {
                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));
                }
            }
        }
示例#15
0
        public void HandleBasicDeliver(string consumerTag,
                                       ulong deliveryTag,
                                       bool redelivered,
                                       string exchange,
                                       string routingKey,
                                       IBasicProperties basicProperties,
                                       byte[] body)
        {
            IBasicConsumer consumer;
            lock (m_consumers)
            {
                consumer = (IBasicConsumer)m_consumers[consumerTag];
            }
            if (consumer == null)
            {
                // FIXME: what is an appropriate thing to do here?
                throw new NotSupportedException("FIXME unsolicited delivery for consumer tag " + consumerTag);
            }

            try {
                consumer.HandleBasicDeliver(consumerTag,
                                            deliveryTag,
                                            redelivered,
                                            exchange,
                                            routingKey,
                                            basicProperties,
                                            body);
            } catch (Exception e) {
                CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                args.Detail["consumer"] = consumer;
                args.Detail["context"] = "HandleBasicDeliver";
                OnCallbackException(args);
            }
        }
        protected void RecoverQueues()
        {
            lock (m_recordedQueues)
            {
                foreach (KeyValuePair<string, RecordedQueue> pair in m_recordedQueues)
                {
                    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.
                        // 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 (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));
                    }
                }
            }
        }
 private static void Connetion_CallbackException(object sender, RabbitMQ.Client.Events.CallbackExceptionEventArgs e)
 {
     Console.WriteLine("Connetion_CallbackException");
 }
 public void HandleBasicConsumeOk(string consumerTag)
 {
     BasicConsumerRpcContinuation k =
         (BasicConsumerRpcContinuation)m_continuationQueue.Next();
     k.m_consumerTag = consumerTag;
     lock (m_consumers)
     {
         m_consumers[consumerTag] = k.m_consumer;
     }
     try {
         k.m_consumer.HandleBasicConsumeOk(consumerTag);
     } catch (Exception e) {
         // FIXME: should we propagate the exception to the
         // caller of BasicConsume?
         CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
         args.Detail["consumer"] = k.m_consumer;
         args.Detail["context"] = "HandleBasicConsumeOk";
         OnCallbackException(args);
     }
     k.HandleCommand(null); // release the continuation.
 }
 public virtual void OnCallbackException(CallbackExceptionEventArgs args)
 {
     m_delegate.OnCallbackException(args);
 }
 ///<summary>Broadcasts notification of the final shutdown of the model.</summary>
 ///<remarks>
 ///<para>
 ///Do not call anywhere other than at the end of OnSessionShutdown.
 ///</para>
 ///<para>
 ///Must not be called when m_closeReason == null, because
 ///otherwise there's a window when a new continuation could be
 ///being enqueued at the same time as we're broadcasting the
 ///shutdown event. See the definition of Enqueue() above.
 ///</para>
 ///</remarks>
 public virtual void OnModelShutdown(ShutdownEventArgs reason)
 {
     //Console.WriteLine("Model shutdown "+((Session)m_session).ChannelNumber+": "+reason);
     m_continuationQueue.HandleModelShutdown(reason);
     ModelShutdownEventHandler handler;
     lock (m_shutdownLock)
     {
         handler = m_modelShutdown;
         m_modelShutdown = null;
     }
     if (handler != null)
     {
         foreach (ModelShutdownEventHandler h in handler.GetInvocationList()) {
             try {
                 h(this, reason);
             } catch (Exception e) {
                 CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                 args.Detail["context"] = "OnModelShutdown";
                 OnCallbackException(args);
             }
         }
     }
     lock (m_unconfirmedSet.SyncRoot)
         Monitor.Pulse(m_unconfirmedSet.SyncRoot);
     m_flowControlBlock.Set();
 }
 public static void OnCallbackException(object sender, CallbackExceptionEventArgs args)
 {
     Console.WriteLine("OnCallbackException ==============================");
     Console.WriteLine("Sender: " + sender);
     Console.WriteLine("Message: " + args.Exception.Message);
     Console.WriteLine("Detail:");
     DebugUtil.DumpProperties(args.Detail, Console.Out, 2);
     Console.WriteLine("----------------------------------------");
 }
 public virtual void OnCallbackException(CallbackExceptionEventArgs args)
 {
     CallbackExceptionEventHandler handler;
     lock (m_eventLock) {
         handler = m_callbackException;
     }
     if (handler != null) {
         foreach (CallbackExceptionEventHandler h in handler.GetInvocationList()) {
             try {
                 h(this, args);
             } catch {
                 // Exception in
                 // Callback-exception-handler. That was the
                 // app's last chance. Swallow the exception.
                 // FIXME: proper logging
             }
         }
     }
 }
 public static CallbackExceptionEventArgs Build(Exception e,
                                                IDictionary<string, object> details)
 {
     var exnArgs = new CallbackExceptionEventArgs(e);
     exnArgs.UpdateDetails(details);
     return exnArgs;
 }
 public virtual void OnBasicRecoverOk(EventArgs args)
 {
     BasicRecoverOkEventHandler handler;
     lock (m_eventLock)
     {
         handler = m_basicRecoverOk;
     }
     if (handler != null)
     {
         foreach (BasicRecoverOkEventHandler h in handler.GetInvocationList())
         {
             try
             {
                 h(this, args);
             }
             catch (Exception e)
             {
                 CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
                 exnArgs.Detail["context"] = "OnBasicRecoverOk";
                 OnCallbackException(exnArgs);
             }
         }
     }
 }
 protected void RunRecoveryEventHandlers()
 {
     EventHandler<EventArgs> handler = m_recovery;
     if (handler != null)
     {
         foreach (EventHandler<EventArgs> reh in handler.GetInvocationList())
         {
             try
             {
                 reh(this, EventArgs.Empty);
             }
             catch (Exception e)
             {
                 var args = new CallbackExceptionEventArgs(e);
                 args.Detail["context"] = "OnConnectionRecovery";
                 m_delegate.OnCallbackException(args);
             }
         }
     }
 }
        public void HandleBasicCancel(string consumerTag, bool nowait)
        {
            IBasicConsumer consumer;
            lock (m_consumers)
            {
                consumer = (IBasicConsumer)m_consumers[consumerTag];
                m_consumers.Remove(consumerTag);
            }
            if (consumer == null)
            {
                consumer = DefaultConsumer;
            }

            try {
                consumer.HandleBasicCancel(consumerTag);
            } catch (Exception e) {
                CallbackExceptionEventArgs args = new CallbackExceptionEventArgs(e);
                args.Detail["consumer"] = consumer;
                args.Detail["context"] = "HandleBasicCancel";
                OnCallbackException(args);
            }
        }
 void _connection_CallbackException(object sender, CallbackExceptionEventArgs e)
 {
 }