void Close(string reason) { if (_log.IsDebugEnabled) { _log.DebugFormat("Closing model: {0} / {1}", _model.ChannelNumber, _connectionContext.HostSettings.ToDebugString()); } try { if (_settings.PublisherConfirmation && _model.IsOpen && _published.Count > 0) { bool timedOut; _model.WaitForConfirms(TimeSpan.FromSeconds(30), out timedOut); if (timedOut) { _log.WarnFormat("Timeout waiting for pending confirms: {0}", _connectionContext.HostSettings.ToDebugString()); } else { _log.DebugFormat("Pending confirms complete: {0}", _connectionContext.HostSettings.ToDebugString()); } } } catch (Exception ex) { _log.Error("Fault waiting for confirms", ex); } _model.Cleanup(200, reason); _participant.SetComplete(); }
/// <summary> /// Called when the broker has received and acknowledged the BasicCancel, indicating /// that the consumer is requesting to be shut down gracefully. /// </summary> /// <param name="consumerTag">The consumerTag that was shut down.</param> void IBasicConsumer.HandleBasicCancelOk(string consumerTag) { if (_log.IsDebugEnabled) { _log.DebugFormat("Consumer Cancel Ok: {0} - {1}", _inputAddress, consumerTag); } _participant.SetComplete(); }
public void DeliveryComplete() { var pendingCount = Interlocked.Decrement(ref _currentPendingDeliveryCount); if (pendingCount == 0 && _shuttingDown) { if (_log.IsDebugEnabled) _log.DebugFormat("Receiver shutdown completed: {0}", _inputAddress); _participant.SetComplete(); } }
async void SetupStopTask() { await Task.Yield(); await _participant.StopRequested; if (_log.IsDebugEnabled) { _log.DebugFormat("Shutting down receiver: {0}", _inputAddress); } _shuttingDown = true; if (_currentPendingDeliveryCount > 0) { try { using (var cancellation = new CancellationTokenSource(_receiveSettings.QueueDescription.LockDuration)) { await _supervisor.Completed .WithCancellation(cancellation.Token).ConfigureAwait(false); } } catch (TaskCanceledException) { if (_log.IsWarnEnabled) { _log.WarnFormat("Timeout waiting for receiver to exit: {0}", _inputAddress); } } } try { await _messageReceiver.CloseAsync(); } catch (Exception) { _participant.SetComplete(); } finally { if (_currentPendingDeliveryCount == 0) { if (_log.IsDebugEnabled) { _log.DebugFormat("Receiver shutdown completed: {0}", _inputAddress); } _participant.SetComplete(); } } }
void HandleDeliveryComplete() { if (_shuttingDown) { if (_log.IsDebugEnabled) { _log.DebugFormat("Receiver shutdown completed: {0}", _clientContext.InputAddress); } _participant.SetComplete(); } }
public Receiver(MessageReceiver messageReceiver, Uri inputAddress, IPipe <ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _messageReceiver = messageReceiver; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _supervisor = supervisor; _participant = supervisor.CreateParticipant(); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentCalls = receiveSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (_log.IsErrorEnabled) { _log.Error($"Exception received on receiver: {_inputAddress} during {x.Action}", x.Exception); } _participant.SetComplete(); }; messageReceiver.OnMessageAsync(OnMessage, options); _participant.SetReady(); SetupStopTask(); }
public Receiver(MessageReceiver messageReceiver, Uri inputAddress, IPipe<ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _messageReceiver = messageReceiver; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _supervisor = supervisor; _participant = supervisor.CreateParticipant(); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentCalls = receiveSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (_log.IsErrorEnabled) _log.Error($"Exception received on receiver: {_inputAddress} during {x.Action}", x.Exception); _participant.SetComplete(); }; messageReceiver.OnMessageAsync(OnMessage, options); _participant.SetReady(); SetupStopTask(); }
async Task Stop() { if (_log.IsDebugEnabled) { _log.DebugFormat("Shutting down consumer: {0}", _inputAddress); } _stopping = true; if (_tracker.ActiveDeliveryCount > 0) { try { using (var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(60))) { await _deliveryComplete.Task.WithCancellation(cancellation.Token).ConfigureAwait(false); } } catch (TaskCanceledException) { if (_log.IsWarnEnabled) { _log.WarnFormat("Timeout waiting for consumer to exit: {0}", _inputAddress); } } } // this has to do something to stop the train, for now, just set complete. _participant.SetComplete(); await _participant.ParticipantCompleted.ConfigureAwait(false); }
public void Dispose() { _connection.ConnectionShutdown -= OnConnectionShutdown; if (_log.IsDebugEnabled) { _log.DebugFormat("Disconnecting: {0}", Description); } _connection.Cleanup(200, "Connection Disposed"); if (_log.IsDebugEnabled) { _log.DebugFormat("Disconnected: {0}", Description); } _participant.SetComplete(); }
public void Dispose() { _connection.ConnectionShutdown -= OnConnectionShutdown; if (_log.IsDebugEnabled) { _log.DebugFormat("Disconnecting: {0}", _hostSettings.ToDebugString()); } Close(200, "Connection Disposed"); if (_log.IsDebugEnabled) { _log.DebugFormat("Disconnected: {0}", _hostSettings.ToDebugString()); } _participant.SetComplete(); }
async Task ReceiveTransportHandle.Stop(CancellationToken cancellationToken) { _participant.SetComplete(); await _supervisor.Stop("Stopped").ConfigureAwait(false); await _supervisor.Completed.ConfigureAwait(false); await _transport._endpointObservable.Completed(new Completed(_transport._inputAddress, _transport._deliveryCount, _transport._maxPendingDeliveryCount)).ConfigureAwait(false); }
async Task ReceiveTransportHandle.Stop(CancellationToken cancellationToken) { _participant.SetComplete(); await _supervisor.Stop("Stopped", cancellationToken).ConfigureAwait(false); await _supervisor.Completed.ConfigureAwait(false); await _transport._transportObservable.Completed(new ReceiveTransportCompletedEvent(_transport._inputAddress, _transport._tracker.GetDeliveryMetrics())).ConfigureAwait(false); }
public SessionReceiver(QueueClient queueClient, Uri inputAddress, IPipe <ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _queueClient = queueClient; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {inputAddress}", Stop); var options = new SessionHandlerOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentSessions = receiveSettings.MaxConcurrentCalls, MessageWaitTimeout = receiveSettings.MessageWaitTimeout }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) { _log.Error($"Exception received on session receiver: {_inputAddress} during {x.Action}", x.Exception); } } if (_currentPendingDeliveryCount == 0) { if (_log.IsDebugEnabled) { _log.DebugFormat("Session receiver shutdown completed: {0}", _inputAddress); } _participant.SetComplete(); } }; IMessageSessionAsyncHandlerFactory handlerFactory = new MessageSessionAsyncHandlerFactory(supervisor, this); queueClient.RegisterSessionHandlerFactoryAsync(handlerFactory, options); _participant.SetReady(); }
public Receiver(NamespaceContext context, ClientContext clientContext, IPipe <ReceiveContext> receivePipe, ClientSettings clientSettings, ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider) { _context = context; _clientContext = clientContext; _receivePipe = receivePipe; _clientSettings = clientSettings; _sendEndpointProvider = sendEndpointProvider; _publishEndpointProvider = publishEndpointProvider; _tracker = new DeliveryTracker(DeliveryComplete); _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {clientContext.InputAddress}", Stop); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = clientSettings.AutoRenewTimeout, MaxConcurrentCalls = clientSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) { _log.Error($"Exception received on receiver: {clientContext.InputAddress} during {x.Action}", x.Exception); } } if (_tracker.ActiveDeliveryCount == 0) { if (_log.IsDebugEnabled) { _log.DebugFormat("Receiver shutdown completed: {0}", clientContext.InputAddress); } _participant.SetComplete(); } }; clientContext.OnMessageAsync(OnMessage, options); _participant.SetReady(); }
public Receiver(ConnectionContext context, MessageReceiver messageReceiver, Uri inputAddress, IPipe <ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _context = context; _messageReceiver = messageReceiver; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {inputAddress}", Stop); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentCalls = receiveSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) { _log.Error($"Exception received on receiver: {_inputAddress} during {x.Action}", x.Exception); } } if (_currentPendingDeliveryCount == 0) { if (_log.IsDebugEnabled) { _log.DebugFormat("Receiver shutdown completed: {0}", _inputAddress); } _participant.SetComplete(); } }; messageReceiver.OnMessageAsync(OnMessage, options); _participant.SetReady(); }
public Receiver(NamespaceContext context, ClientContext clientContext, IPipe<ReceiveContext> receivePipe, ClientSettings clientSettings, ITaskSupervisor supervisor, ISendEndpointProvider sendEndpointProvider, IPublishEndpointProvider publishEndpointProvider) { _context = context; _clientContext = clientContext; _receivePipe = receivePipe; _clientSettings = clientSettings; _sendEndpointProvider = sendEndpointProvider; _publishEndpointProvider = publishEndpointProvider; _tracker = new DeliveryTracker(DeliveryComplete); _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {clientContext.InputAddress}", Stop); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = clientSettings.AutoRenewTimeout, MaxConcurrentCalls = clientSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) _log.Error($"Exception received on receiver: {clientContext.InputAddress} during {x.Action}", x.Exception); } if (_tracker.ActiveDeliveryCount == 0) { if (_log.IsDebugEnabled) _log.DebugFormat("Receiver shutdown completed: {0}", clientContext.InputAddress); _participant.SetComplete(); } }; clientContext.OnMessageAsync(OnMessage, options); _participant.SetReady(); }
void Close(string reason) { if (_log.IsDebugEnabled) { _log.Debug($"Closing client: {_client.BaseAddress}"); } try { _client.Dispose(); } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error("Fault waiting for Dispose", ex); } } _participant.SetComplete(); }
public SessionReceiver(ConnectionContext context, QueueClient queueClient, Uri inputAddress, IPipe<ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _queueClient = queueClient; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {inputAddress}", Stop); var options = new SessionHandlerOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentSessions = receiveSettings.MaxConcurrentCalls, MessageWaitTimeout = receiveSettings.MessageWaitTimeout }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) _log.Error($"Exception received on session receiver: {_inputAddress} during {x.Action}", x.Exception); } if (_currentPendingDeliveryCount == 0) { if (_log.IsDebugEnabled) _log.DebugFormat("Session receiver shutdown completed: {0}", _inputAddress); _participant.SetComplete(); } }; IMessageSessionAsyncHandlerFactory handlerFactory = new MessageSessionAsyncHandlerFactory(context, supervisor, this); queueClient.RegisterSessionHandlerFactoryAsync(handlerFactory, options); _participant.SetReady(); }
public Receiver(ConnectionContext context, MessageReceiver messageReceiver, Uri inputAddress, IPipe<ReceiveContext> receivePipe, ReceiveSettings receiveSettings, IReceiveObserver receiveObserver, ITaskSupervisor supervisor) { _context = context; _messageReceiver = messageReceiver; _inputAddress = inputAddress; _receivePipe = receivePipe; _receiveSettings = receiveSettings; _receiveObserver = receiveObserver; _participant = supervisor.CreateParticipant($"{TypeMetadataCache<Receiver>.ShortName} - {inputAddress}", Stop); var options = new OnMessageOptions { AutoComplete = false, AutoRenewTimeout = receiveSettings.AutoRenewTimeout, MaxConcurrentCalls = receiveSettings.MaxConcurrentCalls }; options.ExceptionReceived += (sender, x) => { if (!(x.Exception is OperationCanceledException)) { if (_log.IsErrorEnabled) _log.Error($"Exception received on receiver: {_inputAddress} during {x.Action}", x.Exception); } if (_currentPendingDeliveryCount == 0) { if (_log.IsDebugEnabled) _log.DebugFormat("Receiver shutdown completed: {0}", _inputAddress); _participant.SetComplete(); } }; messageReceiver.OnMessageAsync(OnMessage, options); _participant.SetReady(); }
void IDisposable.Dispose() { _participant.SetComplete(); }
public void Dispose() { _participant.SetComplete(); }
void ITaskParticipant.SetComplete() { _participant.SetComplete(); }