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")); }
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; }
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); } }
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")); }
public void OnShutDown(RC.ShutdownEventArgs args) { _logger?.LogDebug("OnShutDown"); var listeners = _connectionListeners; foreach (var listener in listeners) { listener.OnShutDown(args); } }
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; }
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); }); }
} // 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
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(); }
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); } }
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; }
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); } }
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 ); }
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); }
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. } }
public void OnShutDown(RC.ShutdownEventArgs args) { _logger?.LogDebug("OnShutDown for connection: {args}", args.ToString()); }
public void OnSessionShutdown(ISession session, ShutdownEventArgs reason) { SetCloseReason(reason); OnModelShutdown(reason); }
///<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(); }
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(); }
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); }
void IBasicConsumer.HandleModelShutdown(object model, ShutdownEventArgs reason) { throw new InvalidOperationException("Should never be called."); }
/// <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(); }
/// <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()); }
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(); }
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; }
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; }
/// <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 }
public override void HandleModelShutdown(object model, ShutdownEventArgs reason) { _callbacksDictionary.Clear(); }
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; }