Exemplo n.º 1
0
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            var inputAddress = context.ConnectionContext.HostSettings.GetInputAddress(receiveSettings);

            using (ITaskScope scope = _supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConsumerFilter>.ShortName} - {inputAddress}", () => TaskUtil.Completed))
            {
                var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receivePipe, _receiveObserver, scope);

                await context.BasicConsume(receiveSettings.QueueName, false, consumer).ConfigureAwait(false);

                await scope.Ready.ConfigureAwait(false);

                await _endpointObserver.Ready(new Ready(inputAddress)).ConfigureAwait(false);

                scope.SetReady();

                try
                {
                    await scope.Completed.ConfigureAwait(false);
                }
                finally
                {
                    RabbitMqConsumerMetrics metrics = consumer;
                    await _endpointObserver.Completed(new Completed(inputAddress, metrics)).ConfigureAwait(false);

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                         metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public RabbitMqModelCache(IConnectionCache connectionCache, ITaskSupervisor supervisor, ModelSettings modelSettings)
        {
            _connectionCache = connectionCache;
            _modelSettings = modelSettings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Exemplo n.º 3
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings          = settings;
            _connectionFactory = settings.GetConnectionFactory();

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConnectionCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Exemplo n.º 4
0
        public RabbitMqModelCache(IConnectionCache connectionCache, ITaskSupervisor supervisor, ModelSettings modelSettings)
        {
            _connectionCache = connectionCache;
            _modelSettings   = modelSettings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Exemplo n.º 5
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;
            _connectionFactory = settings.GetConnectionFactory();

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConnectionCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Exemplo n.º 6
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings, IRabbitMqHostTopology topology, ITaskSupervisor supervisor)
        {
            _settings          = settings;
            _topology          = topology;
            _connectionFactory = new Lazy <ConnectionFactory>(settings.GetConnectionFactory);

            _description = settings.ToDebugString();

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConnectionCache>.ShortName} - {_description}", CloseScope);
        }
        /// <summary>
        /// The basic consumer receives messages pushed from the broker.
        /// </summary>
        /// <param name="model">The model context for the consumer</param>
        /// <param name="inputAddress">The input address for messages received by the consumer</param>
        /// <param name="receivePipe">The receive pipe to dispatch messages</param>
        /// <param name="receiveObserver">The observer for receive events</param>
        /// <param name="taskSupervisor">The token used to cancel/stop the consumer at shutdown</param>
        public RabbitMqBasicConsumer(ModelContext model, Uri inputAddress, IPipe<ReceiveContext> receivePipe, IReceiveObserver receiveObserver,
            ITaskScope taskSupervisor)
        {
            _model = model;
            _inputAddress = inputAddress;
            _receivePipe = receivePipe;
            _receiveObserver = receiveObserver;

            _receiveSettings = model.GetPayload<ReceiveSettings>();

            _pending = new ConcurrentDictionary<ulong, RabbitMqReceiveContext>();

            _participant = taskSupervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqBasicConsumer>.ShortName} - {inputAddress}", Stop);
            _deliveryComplete = new TaskCompletionSource<bool>();
        }
Exemplo n.º 8
0
        /// <summary>
        /// The basic consumer receives messages pushed from the broker.
        /// </summary>
        /// <param name="model">The model context for the consumer</param>
        /// <param name="inputAddress">The input address for messages received by the consumer</param>
        /// <param name="receivePipe">The receive pipe to dispatch messages</param>
        /// <param name="receiveObserver">The observer for receive events</param>
        /// <param name="taskSupervisor">The token used to cancel/stop the consumer at shutdown</param>
        public RabbitMqBasicConsumer(ModelContext model, Uri inputAddress, IPipe <ReceiveContext> receivePipe, IReceiveObserver receiveObserver,
                                     ITaskScope taskSupervisor)
        {
            _model           = model;
            _inputAddress    = inputAddress;
            _receivePipe     = receivePipe;
            _receiveObserver = receiveObserver;

            _receiveSettings = model.GetPayload <ReceiveSettings>();

            _pending = new ConcurrentDictionary <ulong, RabbitMqReceiveContext>();

            _participant      = taskSupervisor.CreateParticipant($"{TypeMetadataCache<RabbitMqBasicConsumer>.ShortName} - {inputAddress}", Stop);
            _deliveryComplete = new TaskCompletionSource <bool>();
        }
Exemplo n.º 9
0
        public HttpConsumerAction(IReceiveObserver receiveObserver,
                                  HttpHostSettings settings,
                                  ReceiveSettings receiveSettings,
                                  IPipe <ReceiveContext> receivePipe,
                                  ITaskScope taskSupervisor,
                                  ISendPipe sendPipe)
        {
            _receiveObserver = receiveObserver;
            _receiveSettings = receiveSettings;
            _receivePipe     = receivePipe;
            _sendPipe        = sendPipe;

            _tracker          = new DeliveryTracker(OnDeliveryComplete);
            _inputAddress     = settings.GetInputAddress();
            _participant      = taskSupervisor.CreateParticipant($"{TypeMetadataCache<HttpConsumerAction>.ShortName} - {_inputAddress}", Stop);
            _deliveryComplete = new TaskCompletionSource <bool>();

            _participant.SetReady();
        }
Exemplo n.º 10
0
        public HttpConsumerAction(IReceiveObserver receiveObserver,
            HttpHostSettings settings,
            ReceiveSettings receiveSettings,
            IPipe<ReceiveContext> receivePipe,
            ITaskScope taskSupervisor,
            ISendPipe sendPipe)
        {
            _receiveObserver = receiveObserver;
            _receiveSettings = receiveSettings;
            _receivePipe = receivePipe;
            _sendPipe = sendPipe;

            _tracker = new DeliveryTracker(OnDeliveryComplete);
            _inputAddress = settings.GetInputAddress();
            _participant = taskSupervisor.CreateParticipant($"{TypeMetadataCache<HttpConsumerAction>.ShortName} - {_inputAddress}", Stop);
            _deliveryComplete = new TaskCompletionSource<bool>();

            _participant.SetReady();
        }
Exemplo n.º 11
0
            public ModelScope(ITaskScope supervisor)
            {
                _modelContext = new TaskCompletionSource<RabbitMqModelContext>();

                _taskScope = supervisor.CreateScope("ModelScope", CloseContext);
            }
Exemplo n.º 12
0
 public HttpClientCache(ITaskSupervisor supervisor, IReceivePipe receivePipe)
 {
     _receivePipe = receivePipe;
     _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<HttpClientCache>.ShortName}", CloseScope);
 }
Exemplo n.º 13
0
            public ClientScope(ITaskScope supervisor)
            {
                _clientContext = new TaskCompletionSource<HttpClientContext>();

                _taskScope = supervisor.CreateScope("ClientScope", CloseContext);
            }
Exemplo n.º 14
0
        public RabbitMqModelCache(IRabbitMqHost host)
        {
            _host = host;

            _cacheTaskScope = host.Supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Exemplo n.º 15
0
            public ConnectionScope(ITaskScope scope, string debugString)
            {
                _connectionContext = new TaskCompletionSource <RabbitMqConnectionContext>();

                _taskScope = scope.CreateScope($"ConnectionScope: {debugString}", CloseContext);
            }
Exemplo n.º 16
0
 public HttpClientContext(HttpClient client, IReceivePipe receivePipe, ITaskScope taskScope)
     : this(client, receivePipe, taskScope.CreateParticipant($"{TypeMetadataCache<HttpClientContext>.ShortName} - {client.BaseAddress}"))
 {
 }
Exemplo n.º 17
0
        public RabbitMqModelCache(IRabbitMqHost host)
        {
            _host = host;

            _cacheTaskScope = host.Supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Exemplo n.º 18
0
        public SharedModelContext(ModelContext context, CancellationToken cancellationToken, ITaskScope scope)
        {
            _context           = context;
            _cancellationToken = cancellationToken;

            _participant = scope.CreateParticipant($"{TypeMetadataCache<SharedModelContext>.ShortName} - {context.ConnectionContext.HostSettings.ToDebugString()}");
            _participant.SetReady();
        }
Exemplo n.º 19
0
        public SharedConnectionContext(ConnectionContext context, CancellationToken cancellationToken, ITaskScope scope)
        {
            _context           = context;
            _cancellationToken = cancellationToken;

            _participant = scope.CreateParticipant($"{TypeMetadataCache<SharedConnectionContext>.ShortName} - {context.Description}");

            _participant.SetReady();
        }
Exemplo n.º 20
0
            public ClientScope(ITaskScope supervisor)
            {
                _clientContext = new TaskCompletionSource <HttpClientContext>();

                _taskScope = supervisor.CreateScope("ClientScope", CloseContext);
            }
Exemplo n.º 21
0
        public OwinHostCache(HttpHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<OwinHostCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Exemplo n.º 22
0
            public OwinHostScope(ITaskScope scope, HttpHostSettings settings)
            {
                _owinHostContext = new TaskCompletionSource<HttpOwinHostContext>();

                _taskScope = scope.CreateScope($"{TypeMetadataCache<OwinHostScope>.ShortName} - {settings.ToDebugString()}", CloseContext);
            }
Exemplo n.º 23
0
 public HttpClientCache(ITaskSupervisor supervisor, IReceivePipe receivePipe)
 {
     _receivePipe    = receivePipe;
     _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<HttpClientCache>.ShortName}", CloseScope);
 }
Exemplo n.º 24
0
            public ModelScope(ITaskScope supervisor)
            {
                _modelContext = new TaskCompletionSource <RabbitMqModelContext>();

                _taskScope = supervisor.CreateScope("ModelScope", CloseContext);
            }
Exemplo n.º 25
0
            public ConnectionScope(ITaskScope scope, RabbitMqHostSettings settings)
            {
                _connectionContext = new TaskCompletionSource <RabbitMqConnectionContext>();

                _taskScope = scope.CreateScope($"ConnectionScope: {settings.ToDebugString()}", CloseContext);
            }
Exemplo n.º 26
0
 public RabbitMqModelContext(ConnectionContext connectionContext, IModel model, ITaskScope taskScope, ModelSettings settings)
     : this(connectionContext, model, settings,
            taskScope.CreateParticipant($"{TypeMetadataCache<RabbitMqModelContext>.ShortName} - {connectionContext.HostSettings.ToDebugString()}"))
 {
 }
Exemplo n.º 27
0
        public OwinHostCache(HttpHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<OwinHostCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Exemplo n.º 28
0
 public RabbitMqModelContext(ConnectionContext connectionContext, IModel model, ITaskScope taskScope, IRabbitMqHost host)
     : this(connectionContext, model, host,
         taskScope.CreateParticipant($"{TypeMetadataCache<RabbitMqModelContext>.ShortName} - {connectionContext.HostSettings.ToDebugString()}"))
 {
 }
Exemplo n.º 29
0
        public SharedHttpClientContext(ClientContext context, CancellationToken cancellationToken, ITaskScope scope)
        {
            _context           = context;
            _cancellationToken = cancellationToken;

            _participant = scope.CreateParticipant($"{TypeMetadataCache<SharedHttpClientContext>.ShortName} - {context.BaseAddress}");

            _participant.SetReady();
        }
Exemplo n.º 30
0
            public OwinHostScope(ITaskScope scope, HttpHostSettings settings)
            {
                _owinHostContext = new TaskCompletionSource <HttpOwinHostContext>();

                _taskScope = scope.CreateScope($"{TypeMetadataCache<OwinHostScope>.ShortName} - {settings.ToDebugString()}", CloseContext);
            }
Exemplo n.º 31
0
            public ConnectionScope(ITaskScope scope, RabbitMqHostSettings settings)
            {
                _connectionContext = new TaskCompletionSource<RabbitMqConnectionContext>();

                _taskScope = scope.CreateScope($"ConnectionScope: {settings.ToDebugString()}", CloseContext);
            }