Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        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();
                }
            }
        }
Exemplo n.º 5
0
        void HandleDeliveryComplete()
        {
            if (_shuttingDown)
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Receiver shutdown completed: {0}", _clientContext.InputAddress);
                }

                _participant.SetComplete();
            }
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 11
0
            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);
            }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        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();
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
0
        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();
        }
Exemplo n.º 18
0
        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();
        }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
 void IDisposable.Dispose()
 {
     _participant.SetComplete();
 }
Exemplo n.º 21
0
 public void Dispose()
 {
     _participant.SetComplete();
 }
Exemplo n.º 22
0
 void ITaskParticipant.SetComplete()
 {
     _participant.SetComplete();
 }