Пример #1
0
 public void HandleModelShutdown(IModel model, ShutdownEventArgs reason)
 {
     if (ModelShutdown != null)
     {
         ModelShutdown(this, new ModelShutdownEventArgs(model, reason));
     }
 }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            channel = MockRepository.GenerateStub<IModel>();
            var eventBus = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer, 
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);
            var first = true;

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
                {
                    if (first)
                    {
                        first = false;
                        throw exception;
                    }
                    x.ReturnValue = channel;
                });

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Пример #3
0
        public static bool IsMismatchedQueueArgs(Exception exception)
        {
            var cause = exception;

            RC.ShutdownEventArgs args = null;
            while (cause != null && args == null)
            {
                if (cause is ShutdownSignalException)
                {
                    args = ((ShutdownSignalException)cause).Args;
                }

                if (cause is OperationInterruptedException)
                {
                    args = ((OperationInterruptedException)cause).ShutdownReason;
                }

                cause = cause.InnerException;
            }

            if (args == null)
            {
                return(false);
            }
            else
            {
                return(IsMismatchedQueueArgs(args));
            }
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            var eventBus = MockRepository.GenerateStub<IEventBus>();

            var configuration = new ConnectionConfiguration
                {
                    Timeout = 1
                };

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
                {
                    throw exception;
                });

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

        }
 public QuiescingSession(Connection connection,
     int channelNumber,
     ShutdownEventArgs reason)
     : base(connection, channelNumber)
 {
     m_reason = reason;
 }
Пример #6
0
            public override void HandleModelShutdown(object model, RC.ShutdownEventArgs reason)
            {
                base.HandleModelShutdown(model, reason);

                Logger?.LogDebug("Received shutdown signal for consumer tag: {tag} reason: {reason}", ConsumerTag, reason.ReplyText);
                Consumer.Shutdown = reason;
                Consumer.DeliveryTags.Clear();
                Consumer.ActiveObjectCounter.Release(Consumer);
            }
        public void OnShutDown(RC.ShutdownEventArgs @event)
        {
            _logger?.LogDebug("OnShutDown");
            var listeners = _channelListeners;

            foreach (var listener in listeners)
            {
                listener.OnShutDown(@event);
            }
        }
Пример #8
0
 public static bool IsNormalShutdown(RC.ShutdownEventArgs args)
 {
     return((args.ClassId == ConnectionClose_ClassId &&
             args.MethodId == ConnectionClose_MethodId &&
             args.ReplyCode == ReplySuccess &&
             args.ReplyText == "OK") ||
            (args.Initiator == RC.ShutdownInitiator.Application &&
             args.ClassId == 0 && args.MethodId == 0 &&
             args.ReplyText == "Goodbye"));
 }
Пример #9
0
        public void OnShutDown(RC.ShutdownEventArgs args)
        {
            _logger?.LogDebug("OnShutDown");
            var listeners = _connectionListeners;

            foreach (var listener in listeners)
            {
                listener.OnShutDown(args);
            }
        }
Пример #10
0
        private void ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
        {
            if (Disconnected != null) Disconnected();

            _watcher.WarnFormat("Disconnected from RabbitMQ Broker");

            if (reason != null && reason.ReplyText != "Connection disposed by application")
            {
                _retryPolicy.WaitForNextRetry(Connect);
            }
        }
 public QuiescingSession(ConnectionBase connection,
                         int channelNumber,
                         ShutdownEventArgs reason,
                         int replyClassId,
                         int replyMethodId)
     : base(connection, channelNumber)
 {
     m_reason = reason;
     m_replyClassId = replyClassId;
     m_replyMethodId = replyMethodId;
 }
Пример #12
0
        public void SetUp()
        {
            mockBuilder = new MockBuilder("host=localhost;timeout=1");

            mockBuilder.NextModel
                .Stub(x => x.ExchangeDeclare(null, null, false, false, null))
                .IgnoreArguments()
                .WhenCalled(x =>
                    {
                        var args = new ShutdownEventArgs(ShutdownInitiator.Peer, 320, 
                            "CONNECTION_FORCED - Closed via management plugin");
                        throw new OperationInterruptedException(args);
                    });
        }
Пример #13
0
        } // ConnectionHandlerProgram

        #endregion ConnectionHandlerProgram


        #region Event handlers

        private void ModelShutdown(object sender, RmqCl.ShutdownEventArgs args)
        {
            if (m_disposed.Value)
            {
                // No need to react because dispose has already been called
                return;
            }

            SendConnectionEvent(true, ConnectionEventType.ConnectionLost);

            // These will trigger connection restore
            m_triggerConnectionRestore.Value = true;
            TriggerWorkerThread();
        } // ModelShutdown
Пример #14
0
 void Connection_ConnectionShutdown(object source, ShutdownEventArgs reason)
 {
     consumer.ConnectionLost -= Connection_ConnectionShutdown;
     log.Debug("CarService: Connection lost to RabbitMQ Server due to {0}", reason.Cause);
     try
     {
         consumer.StopConsuming();
     }
     catch (Exception ex)
     {
         log.Warning(ex, "CarService: Shutting down old connection to allow new connection to replace it");
     }
     InitializeQueueConnection();
     ProcessingService.StartConsumer();
 }
Пример #15
0
 public virtual void OnSessionShutdown(ShutdownEventArgs reason)
 {
     //Console.WriteLine("Session shutdown "+ChannelNumber+": "+reason);
     m_connection.ConnectionShutdown -=
         new ConnectionShutdownEventHandler(this.OnConnectionShutdown);
     SessionShutdownEventHandler handler;
     lock (m_shutdownLock)
     {
         handler = m_sessionShutdown;
         m_sessionShutdown = null;
     }
     if (handler != null)
     {
         handler(this, reason);
     }
 }
Пример #16
0
 void ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
 {
     "The connection to the rabbitmq node is shutting down. \r\n\t Class: {0} \r\n\t Method: {1} \r\n\t Cause: {2} \r\n\t Reply {3}: {4}"
         .ToError<IBus>
         (
             reason.ClassId,
             reason.MethodId,
             reason.Cause,
             reason.ReplyCode,
             reason.ReplyText
         );
     connection.ConnectionShutdown -= ConnectionShutdown;
     _connection = null;
     connection.Dispose();
     connection = null;
 }
Пример #17
0
        private void SharedConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
        {
            if (Disconnected != null) Disconnected();

            _watcher.WarnFormat("Disconnected from RabbitMQ Broker");

            foreach(var c in SharedConnections)
            {
                if (c.Key == ConnectionFactory.Endpoint + ConnectionFactory.VirtualHost)
                {
                    SharedConnections.Remove(c.Key);
                    break;
                }
            }

            if (reason != null && reason.ReplyText != "Connection disposed by application" && reason.ReplyText != Subscription.CloseByApplication)
            {
                _retryPolicy.WaitForNextRetry(Connect);
            }
        }
Пример #18
0
        public static bool IsPassiveDeclarationChannelClose(Exception exception)
        {
            RC.ShutdownEventArgs cause = null;
            if (exception is ShutdownSignalException)
            {
                cause = ((ShutdownSignalException)exception).Args;
            }
            else if (exception is ProtocolException)
            {
                cause = ((ProtocolException)exception).ShutdownReason;
            }

            if (cause != null)
            {
                return((cause.ClassId == Exchange_ClassId || cause.ClassId == Queue_ClassId) &&
                       cause.MethodId == Declare_MethodId &&
                       cause.ReplyCode == NotFound);
            }

            return(false);
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            channel = MockRepository.GenerateStub<IModel>();
            var eventBus = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).Throw(exception).Repeat.Once();
            persistentConnection.Stub(x => x.CreateModel()).Return(channel).Repeat.Any();

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow );
        }
Пример #20
0
        internal static bool IsExchangeDeclarationFailure(RabbitIOException e)
        {
            Exception cause = e;

            RC.ShutdownEventArgs args = null;
            while (cause != null && args == null)
            {
                if (cause is OperationInterruptedException)
                {
                    args = ((OperationInterruptedException)cause).ShutdownReason;
                }

                cause = cause.InnerException;
            }

            if (args == null)
            {
                return(false);
            }

            return(args.ClassId == Exchange_ClassId &&
                   args.MethodId == Declare_MethodId &&
                   args.ReplyCode == Command_Invalid);
        }
 public void HandleModelShutdown(object model, R.ShutdownEventArgs reason)
 {
     throw new NotImplementedException();
 }
 public void Close(ShutdownEventArgs reason)
 {
     Close(reason, false, Timeout.Infinite);
 }
Пример #23
0
 public void HandleConnectionClose(ushort replyCode,
                                   string replyText,
                                   ushort classId,
                                   ushort methodId)
 {
     ShutdownEventArgs reason = new ShutdownEventArgs(ShutdownInitiator.Peer,
                                                      replyCode,
                                                      replyText,
                                                      classId,
                                                      methodId);
     try
     {
         ((ConnectionBase)m_session.Connection).InternalClose(reason);
         _Private_ConnectionCloseOk();
         SetCloseReason((m_session.Connection).CloseReason);
     }
     catch (IOException)
     {
         // Ignored. We're only trying to be polite by sending
         // the close-ok, after all.
     }
     catch (AlreadyClosedException)
     {
         // Ignored. We're only trying to be polite by sending
         // the close-ok, after all.
     }
 }
Пример #24
0
 public void OnShutDown(RC.ShutdownEventArgs args)
 {
     _logger?.LogDebug("OnShutDown for connection: {args}", args.ToString());
 }
Пример #25
0
 public void OnSessionShutdown(ISession session, ShutdownEventArgs reason)
 {
     SetCloseReason(reason);
     OnModelShutdown(reason);
 }
Пример #26
0
 ///<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();
 }
 /// <summary>
 /// Handle model shutdown, given a consumerTag.
 /// </summary>
 /// <param name="consumerTag">
 /// The consumer tag.
 /// </param>
 /// <param name="sig">
 /// The sig.
 /// </param>
 public void HandleModelShutdown(string consumerTag, ShutdownEventArgs sig)
 {
     if (this.logger.IsDebugEnabled)
     {
         logger.Debug("Received shutdown signal for consumer tag=" + consumerTag + " , cause=" + sig.Cause);
     }
     outer.shutdown = sig;
 }
        void OnModelShutdown(object model, ShutdownEventArgs reason)
        {
            _model.ModelShutdown -= OnModelShutdown;
            _model.BasicAcks -= OnBasicAcks;
            _model.BasicNacks -= OnBasicNacks;
            _model.BasicReturn -= OnBasicReturn;

            FaultPendingPublishes();

            _participant.SetComplete();
        }
        public void InternalClose(ShutdownEventArgs reason)
        {
            if (!SetCloseReason(reason))
            {
                if (m_closed)
                    throw new AlreadyClosedException(m_closeReason);
                // We are quiescing, but still allow for server-close
            }

            OnShutdown();
            m_session0.SetSessionClosing(true);
            TerminateMainloop();
        }
        ///<summary>Try to close connection in a graceful way</summary>
        ///<remarks>
        ///<para>
        ///Shutdown reason contains code and text assigned when closing the connection,
        ///as well as the information about what initiated the close
        ///</para>
        ///<para>
        ///Abort flag, if true, signals to close the ongoing connection immediately 
        ///and do not report any errors if it was already closed.
        ///</para>
        ///<para>
        ///Timeout determines how much time internal close operations should be given
        ///to complete. Negative or Timeout.Infinite value mean infinity.
        ///</para>
        ///</remarks>
        public void Close(ShutdownEventArgs reason, bool abort, int timeout)
        {
            if (!SetCloseReason(reason))
            {
               if (!abort)
                    throw new AlreadyClosedException(m_closeReason);
            }
            else
            {
                OnShutdown();
                m_session0.SetSessionClosing(false);

                try
                {
                    // Try to send connection.close
                    // Wait for CloseOk in the MainLoop
                    m_session0.Transmit(ConnectionCloseWrapper(reason.ReplyCode,
                                                              reason.ReplyText));
                }
                catch (AlreadyClosedException ace)
                {
                    if (!abort)
                        throw ace;
                }
                catch (IOException ioe)
                {
                    if (m_model0.CloseReason == null)
                    {
                        if (!abort)
                            throw ioe;
                        else
                            LogCloseError("Couldn't close connection cleanly. "
                                          + "Socket closed unexpectedly", ioe);
                    }
                }
                finally
                {
                    TerminateMainloop();
                }
            }
            if (!m_appContinuation.WaitOne(BlockingCell.validatedTimeout(timeout),true))
                m_frameHandler.Close();
        }
Пример #31
0
 public static bool IsMismatchedQueueArgs(RC.ShutdownEventArgs args)
 {
     return(args.ClassId == Queue_ClassId &&
            args.MethodId == Declare_MethodId &&
            args.ReplyCode == Precondition_Failed);
 }
 ///<summary>Default implementation - sets ShutdownReason and
 ///calls OnCancel().</summary>
 public virtual void HandleModelShutdown(IModel model, ShutdownEventArgs reason)
 {
     m_shutdownReason = reason;
     OnCancel();
 }
Пример #33
0
 public void OnShutDown(RC.ShutdownEventArgs args)
 {
 }
        public void HandleMainLoopException(ShutdownEventArgs reason)
        {
            if (!SetCloseReason(reason))
            {
                LogCloseError("Unexpected Main Loop Exception while closing: "
                               + reason.ToString(), null);
                return;
            }

            OnShutdown();
            LogCloseError("Unexpected connection closure: " + reason.ToString(), null);
        }
 /// <summary>
 /// Called when the model (channel) this consumer was registered on terminates.
 /// </summary>
 /// <param name="model">A channel this consumer was registered on.</param>
 /// <param name="reason">Shutdown context.</param>
 public virtual Task HandleModelShutdown(object model, ShutdownEventArgs reason)
 {
     ShutdownReason = reason;
     return(OnCancel(_consumerTags.ToArray()));
 }
 public virtual void HandleModelShutdown(ShutdownEventArgs reason)
 {
     m_cell.Value = Either.Right(reason);
 }
Пример #37
0
 void IBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason)
 {
     throw new InvalidOperationException("Should never be called.");
 }
Пример #38
0
 /// <summary>
 ///  Called when the model shuts down.
 ///  </summary>
 ///  <param name="model"> Common AMQP model.</param>
 /// <param name="reason"> Information about the reason why a particular model, session, or connection was destroyed.</param>
 public virtual void HandleModelShutdown(object model, ShutdownEventArgs reason)
 {
     ShutdownReason = reason;
     OnCancel();
 }
Пример #39
0
 /// <summary>
 ///  Called when the model shuts down.
 ///  </summary>
 ///  <param name="model"> Common AMQP model.</param>
 /// <param name="reason"> Information about the reason why a particular model, session, or connection was destroyed.</param>
 public virtual Task HandleModelShutdown(object model, ShutdownEventArgs reason)
 {
     ShutdownReason = reason;
     return(OnCancel());
 }
Пример #40
0
        public void Close(ShutdownEventArgs reason, bool abort)
        {
            ShutdownContinuation k = new ShutdownContinuation();
            ModelShutdown += new ModelShutdownEventHandler(k.OnShutdown);

            try {
                if (SetCloseReason(reason))
                {
                    _Private_ChannelClose(reason.ReplyCode, reason.ReplyText, 0, 0);
                }
                k.Wait();
            } catch (AlreadyClosedException ace) {
                if (!abort)
                    throw ace;
            } catch (IOException ioe) {
                if (!abort)
                    throw ioe;
            }
        }
 public void OnShutDown(RC.ShutdownEventArgs args)
 {
     throw new NotImplementedException();
 }
Пример #42
0
 public bool SetCloseReason(ShutdownEventArgs reason)
 {
     lock (m_shutdownLock)
     {
         if (m_closeReason == null)
         {
             m_closeReason = reason;
             return true;
         }
         else
         {
             return false;
         }
     }
 }
 // You will note there are two practically identical overloads
 // of OnShutdown() here. This is because Microsoft's C#
 // compilers do not consistently support the Liskov
 // substitutability principle. When I use
 // OnShutdown(object,ShutdownEventArgs), the compilers
 // complain that OnShutdown can't be placed into a
 // ConnectionShutdownEventHandler because object doesn't
 // "match" IConnection, even though there's no context in
 // which the program could Go Wrong were it to accept the
 // code. The same problem appears for
 // ModelShutdownEventHandler. The .NET 1.1 compiler complains
 // about these two cases, and the .NET 2.0 compiler does not -
 // presumably they improved the type checker with the new
 // release of the compiler.
 public virtual void OnShutdown(IConnection sender, ShutdownEventArgs reason)
 {
     m_cell.Value = reason;
 }
Пример #44
0
 public void HandleConnectionStart(byte versionMajor,
                                   byte versionMinor,
                                   IDictionary<string, object> serverProperties,
                                   byte[] mechanisms,
                                   byte[] locales)
 {
     if (m_connectionStartCell == null)
     {
         ShutdownEventArgs reason =
             new ShutdownEventArgs(ShutdownInitiator.Library,
                                   CommonFraming.Constants.CommandInvalid,
                                   "Unexpected Connection.Start");
         ((ConnectionBase)m_session.Connection).Close(reason);
     }
     ConnectionStartDetails details = new ConnectionStartDetails();
     details.m_versionMajor = versionMajor;
     details.m_versionMinor = versionMinor;
     details.m_serverProperties = serverProperties;
     details.m_mechanisms = mechanisms;
     details.m_locales = locales;
     m_connectionStartCell.Value = details;
     m_connectionStartCell = null;
 }
 public virtual void OnShutdown(IModel sender, ShutdownEventArgs reason)
 {
     m_cell.Value = reason;
 }
Пример #46
0
 /// <summary>
 /// For example Model can be shut-down when we f**k up consumer
 /// ACK non existing deliverTag, ACK twice the same delivery tag, unbind queue that was no bound
 /// </summary>
 /// <param name="model"></param>
 /// <param name="reason"></param>
 protected virtual void OutboundChannel_ModelShutdown( IModel model, ShutdownEventArgs reason )
 {
     this.Tracer.TraceEvent ( System.Diagnostics.TraceEventType.Error, 0, "[{0}] channel shutdow {1} reason {2} ", this, model, reason.ToString () );
     //TODO:react depending on the reason: reconnect or discharge all pending RPC requests
 }
Пример #47
0
 public override void HandleModelShutdown(object model, ShutdownEventArgs reason)
 {
     _callbacksDictionary.Clear();
 }
Пример #48
0
        void OnConnectionShutdown(object sender, ShutdownEventArgs e)
        {
            if (disposed) return;
            OnDisconnected();

            // try to reconnect and re-subscribe
            logger.InfoWrite("Disconnected from RabbitMQ Broker");

            TryToConnect(null);
        }
 public ShutdownSignalException(RC.ShutdownEventArgs args)
 {
     _args = args;
 }