Exemplo n.º 1
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            var decoratorRegistration = configurationServiceProvider.GetService <IConsumerFactoryDecoratorRegistration <TConsumer> >();

            if (decoratorRegistration != null)
            {
                consumerFactory = decoratorRegistration.DecorateConsumerFactory(consumerFactory);
            }

            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            var endpointName = configurator.InputAddress.GetLastPart();

            foreach (var configureReceiveEndpoint in consumerConfigurator.SelectOptions <IConfigureReceiveEndpoint>())
            {
                configureReceiveEndpoint.Configure(endpointName, configurator);
            }

            LogContext.Info?.Log("Configured endpoint {Endpoint}, Consumer: {ConsumerType}", endpointName, TypeMetadataCache <TConsumer> .ShortName);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 2
0
        void ConfigureSuperviseJobConsumer(IReceiveEndpointConfigurator configurator)
        {
            var consumerFactory = new DelegateConsumerFactory <SuperviseJobConsumer>(() => new SuperviseJobConsumer(this));

            var consumerConfigurator = new ConsumerConfigurator <SuperviseJobConsumer>(consumerFactory, configurator);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
        void ConfigureStartJobConsumer(IReceiveEndpointConfigurator configurator, JobOptions <TJob> options, IJobService jobService,
                                       IPipe <ConsumeContext <TJob> > pipe)
        {
            var consumerFactory = new DelegateConsumerFactory <StartJobConsumer <TJob> >(() => new StartJobConsumer <TJob>(jobService, options, pipe));

            var consumerConfigurator = new ConsumerConfigurator <StartJobConsumer <TJob> >(consumerFactory, configurator);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 4
0
        public ReceivedMessageList <T> Fault <T>()
            where T : class
        {
            var consumer  = new FaultOf <T>(this);
            var configure = new ConsumerConfigurator <T>(consumer);

            _configures.Add(configure);

            return(consumer.Received);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Connect a consumer to the receiving endpoint
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="consumerFactory"></param>
        /// <param name="configure">Optional, configure the consumer</param>
        /// <returns></returns>
        public static void Consumer<TConsumer>(this IReceiveEndpointConfigurator configurator, IConsumerFactory<TConsumer> consumerFactory,
            Action<IConsumerConfigurator<TConsumer>> configure = null)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
                _log.DebugFormat("Subscribing Consumer: {0} (using supplied consumer factory)", TypeMetadataCache<TConsumer>.ShortName);

            var consumerConfigurator = new ConsumerConfigurator<TConsumer>(consumerFactory, configurator);

            configure?.Invoke(consumerConfigurator);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Subscribes a consumer with a default constructor to the endpoint
        /// </summary>
        /// <typeparam name="TConsumer">The consumer type</typeparam>
        /// <param name="configurator"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <TConsumer>(this IReceiveEndpointConfigurator configurator, Action <IConsumerConfigurator <TConsumer> > configure = null)
            where TConsumer : class, IConsumer, new()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using default constructor)", TypeMetadataCache <TConsumer> .ShortName);
            }

            var consumerFactory = new DefaultConstructorConsumerFactory <TConsumer>();

            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory);

            configure?.Invoke(consumerConfigurator);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 7
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider        = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            var consumerFactory      = new ScopeConsumerFactory <TConsumer>(scopeProvider);
            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Subscribes a consumer with a default constructor to the endpoint
        /// </summary>
        /// <typeparam name="TConsumer">The consumer type</typeparam>
        /// <param name="configurator"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <TConsumer>(this IReceiveEndpointConfigurator configurator, Action <IConsumerConfigurator <TConsumer> > configure = null)
            where TConsumer : class, IConsumer, new()
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            LogContext.Debug?.Log("Subscribing Consumer: {ConsumerType} (using default constructor)", TypeMetadataCache <TConsumer> .ShortName);

            var consumerFactory = new DefaultConstructorConsumerFactory <TConsumer>();

            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            configure?.Invoke(consumerConfigurator);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
Exemplo n.º 9
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider        = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            var consumerFactory      = new ScopeConsumerFactory <TConsumer>(scopeProvider);
            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            LogContext.Debug?.Log("Configuring endpoint {Endpoint}, Consumer: {ConsumerType}", configurator.InputAddress.GetLastPart(),
                                  TypeMetadataCache <TConsumer> .ShortName);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            configurator.AddEndpointSpecification(consumerConfigurator);
        }