Example #1
0
        public RabbitMqConnectionCache(RabbitMqHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings          = settings;
            _connectionFactory = settings.GetConnectionFactory();

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

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<RabbitMqModelCache>.ShortName}", CloseScope);
        }
Example #3
0
        public async Task Send(OwinHostContext context, IPipe <OwinHostContext> next)
        {
            var inputAddress = context.HostSettings.GetInputAddress();

            using (var scope = _supervisor.CreateScope($"{TypeMetadataCache<HttpConsumerFilter>.ShortName} - {inputAddress}", () => TaskUtil.Completed))
            {
                var controller = new HttpConsumerAction(_receiveObserver, _hostSettings, _receiveSettings, _receivePipe, scope, _sendPipe);

                context.RegisterEndpointHandler(_receiveSettings.PathMatch, controller);

                await scope.Ready.ConfigureAwait(false);

                await _transportObserver.Ready(new ReceiveTransportReadyEvent(inputAddress)).ConfigureAwait(false);

                scope.SetReady();

                try
                {
                    await scope.Completed.ConfigureAwait(false);
                }
                finally
                {
                    HttpConsumerMetrics metrics = controller;
                    await _transportObserver.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0} received, {1} concurrent", metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
Example #4
0
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

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

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

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

                await scope.Ready.ConfigureAwait(false);

                await _transportObserver.Ready(new ReceiveTransportReadyEvent(inputAddress)).ConfigureAwait(false);

                scope.SetReady();

                try
                {
                    await scope.Completed.ConfigureAwait(false);
                }
                finally
                {
                    RabbitMqDeliveryMetrics metrics = consumer;
                    await _transportObserver.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                         metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
Example #5
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);
        }
Example #7
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);
        }
Example #8
0
        public static ITaskScope CreateScope(this ITaskSupervisor supervisor, string tag, Func <Task> afterStopped)
        {
            var scope = supervisor.CreateScope(tag);

            scope.StopRequested.ContinueWith(async stopTask =>
            {
                var stopEvent = await stopTask.ConfigureAwait(false);

                await scope.Stop(stopEvent.Reason, afterStopped).ConfigureAwait(false);
            }, TaskScheduler.Default);

            return(scope);
        }
Example #9
0
        async Task IFilter <ConnectionContext> .Send(ConnectionContext context, IPipe <ConnectionContext> next)
        {
            using (var scope = _supervisor.CreateScope($"{TypeMetadataCache<ReceiveModelFilter>.ShortName}"))
            {
                var model = await context.CreateModel().ConfigureAwait(false);

                using (var modelContext = new RabbitMqModelContext(context, model, scope, _host))
                {
                    await _pipe.Send(modelContext).ConfigureAwait(false);
                }

                await scope.Completed.ConfigureAwait(false);

                await next.Send(context).ConfigureAwait(false);
            }
        }
Example #10
0
 ITaskScope NamespaceContext.CreateScope(string tag)
 {
     return(_supervisor.CreateScope(tag));
 }
 public HttpClientCache(ITaskSupervisor supervisor, IReceivePipe receivePipe)
 {
     _receivePipe = receivePipe;
     _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<HttpClientCache>.ShortName}", CloseScope);
 }
Example #12
0
        public OwinHostCache(HttpHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<OwinHostCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Example #13
0
        public OwinHostCache(HttpHostSettings settings, ITaskSupervisor supervisor)
        {
            _settings = settings;

            _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<OwinHostCache>.ShortName} - {settings.ToDebugString()}", CloseScope);
        }
Example #14
0
 public HttpClientCache(ITaskSupervisor supervisor, IReceivePipe receivePipe)
 {
     _receivePipe    = receivePipe;
     _cacheTaskScope = supervisor.CreateScope($"{TypeMetadataCache<HttpClientCache>.ShortName}", CloseScope);
 }