public ConsumerSubscriptionBuilder(IConsumerFactory <TConsumer> consumerFactory,
                                           Func <UnsubscribeAction, ISubscriptionReference> referenceFactory)
        {
            _consumerFactory  = consumerFactory;
            _referenceFactory = referenceFactory;

            _consumerConnector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();
        }
        public ConsumerSubscriptionBuilder(IConsumerFactory <TConsumer> consumerFactory,
                                           ReferenceFactory referenceFactory)
        {
            _consumerFactory  = consumerFactory;
            _referenceFactory = referenceFactory;

            _consumerConnector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();
        }
        /// <summary>
        /// Subscribe a component type to the pipeline that is resolved from the container for each message
        /// </summary>
        /// <typeparam name="TComponent"></typeparam>
        /// <param name="pipeline">The pipeline to configure</param>
        /// <returns></returns>
        public static UnsubscribeAction ConnectConsumer <TComponent>(this IInboundMessagePipeline pipeline)
            where TComponent : class, new()
        {
            return(pipeline.Configure(x =>
            {
                var consumerFactory = new DelegateConsumerFactory <TComponent>(() => new TComponent());

                ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TComponent>();
                return connector.Connect(x, consumerFactory);
            }));
        }
        /// <summary>
        /// Subscribe a component type to the pipeline that is resolved from the container for each message
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <param name="pipeline">The pipeline to configure</param>
        /// <param name="consumerFactory"></param>
        /// <returns></returns>
        public static UnsubscribeAction ConnectConsumer <TConsumer>(this IInboundMessagePipeline pipeline,
                                                                    Func <TConsumer> consumerFactory)
            where TConsumer : class
        {
            return(pipeline.Configure(x =>
            {
                var factory = new DelegateConsumerFactory <TConsumer>(consumerFactory);

                ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();
                return connector.Connect(x, factory);
            }));
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                      [NotNull] IConsumerFactory <TConsumer>
                                                                      consumerFactory)
            where TConsumer : class
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using supplied consumer factory)", typeof(TConsumer));
            }

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, consumerFactory)));
        }
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus)
            where TConsumer : class, new()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using default consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(() => new TConsumer());

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, delegateConsumerFactory)));
        }
        public static UnsubscribeAction SubscribeConsumer([NotNull] this IServiceBus bus, [NotNull] Type consumerType,
                                                          [NotNull] Func <Type, object> consumerFactory)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (by type, using object consumer factory)", consumerType);
            }

            object factory = FastActivator.Create(typeof(ObjectConsumerFactory <>), new[] { consumerType },
                                                  new object[] { consumerFactory });

            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector(consumerType);

            return(bus.Configure(x => connector.FastInvoke <ConsumerConnector, UnsubscribeAction>("Connect", x, factory)));
        }
        public static UnsubscribeAction SubscribeInterceptingConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                                  [NotNull] Func <TConsumer> consumerFactory, [NotNull] Action <Action> interceptor)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using delegate consumer factory)", typeof(TConsumer));
            }

            var delegateConsumerFactory = new DelegateConsumerFactory <TConsumer>(consumerFactory);

            var interceptingConsumerFactory = new InterceptingConsumerFactory <TConsumer>(delegateConsumerFactory,
                                                                                          interceptor);
            ConsumerConnector connector = ConsumerConnectorCache.GetConsumerConnector <TConsumer>();

            return(bus.Configure(x => connector.Connect(x, interceptingConsumerFactory)));
        }
        private void InitializeConsumerConnection(string tenant, string product, string component, string topic, string consumer)
        {
            string consumerKey = $"{tenant}~{product}~{component}~{topic}~{consumer}";

            try
            {
                if (connectors.ContainsKey(consumerKey))
                {
                    return;
                }

                var connector = new ConsumerConnector(_logger, tenant, product, component, topic, consumer, new ConsumerPointerContext(ConsumerLocations.GetConsumerPointerFile(tenant,
                                                                                                                                                                                product, component, topic, consumer)), _partitionConfiguration, _agentConfiguration.MaxNumber);

                connectors.TryAdd(consumerKey, connector);
            }
            catch (Exception)
            {
                _logger.LogError($"Failed to create consumer connector at '{consumerKey}'");
            }
        }
Exemplo n.º 10
0
        public void A_consumer_with_consumes_all_interfaces_is_inspected()
        {
            _consumerFactory = new DelegateConsumerFactory <Consumer>(() => new Consumer());

            _factory = new ConsumerConnector <Consumer>();
        }