Esempio 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);
                    }
                }
            }
        }
Esempio n. 2
0
        public RabbitMqModelCache(IConnectionCache connectionCache, ITaskSupervisor supervisor, ModelSettings modelSettings)
        {
            _connectionCache = connectionCache;
            _modelSettings = modelSettings;

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

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

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

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConnectionCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Esempio 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>();
        }
Esempio 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>();
        }
Esempio 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();
        }
        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();
        }
Esempio n. 11
0
            public ModelScope(ITaskScope supervisor)
            {
                _modelContext = new TaskCompletionSource<RabbitMqModelContext>();

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

                _taskScope = supervisor.CreateScope("ClientScope", CloseContext);
            }
        public RabbitMqModelCache(IRabbitMqHost host)
        {
            _host = host;

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

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

            _cacheTaskScope = host.Supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Esempio 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();
        }
Esempio 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();
        }
Esempio n. 20
0
            public ClientScope(ITaskScope supervisor)
            {
                _clientContext = new TaskCompletionSource <HttpClientContext>();

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

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

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

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

                _taskScope = scope.CreateScope($"ConnectionScope: {settings.ToDebugString()}", CloseContext);
            }
Esempio 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()}"))
 {
 }
Esempio n. 27
0
        public OwinHostCache(HttpHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<OwinHostCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
 public RabbitMqModelContext(ConnectionContext connectionContext, IModel model, ITaskScope taskScope, IRabbitMqHost host)
     : this(connectionContext, model, host,
         taskScope.CreateParticipant($"{TypeMetadataCache<RabbitMqModelContext>.ShortName} - {connectionContext.HostSettings.ToDebugString()}"))
 {
 }
Esempio 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();
        }
Esempio n. 30
0
            public OwinHostScope(ITaskScope scope, HttpHostSettings settings)
            {
                _owinHostContext = new TaskCompletionSource <HttpOwinHostContext>();

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

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