コード例 #1
0
        public static UnsubscribeAction SubscribeConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                      [NotNull] Func <TConsumer> consumerFactory)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using delegate consumer factory)", typeof(TConsumer));
            }

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

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

            return(bus.Configure(x => connector.Connect(x, delegateConsumerFactory)));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        public static UnsubscribeAction SubscribeInterceptingConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                                  [NotNull] IConsumerFactory <TConsumer> consumerFactory, [NotNull] Action <Action> interceptor)
            where TConsumer : class, IConsumer
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using supplied consumer factory)", typeof(TConsumer));
            }

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

            return(bus.Configure(x => connector.Connect(x, interceptingConsumerFactory)));
        }
コード例 #4
0
        /// <summary>
        /// Connect a consumer with a consumer type and object factory method for the consumer
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="consumerType"></param>
        /// <param name="objectFactory"></param>
        /// <returns></returns>
        public static ConnectHandle ConnectConsumer(this IConsumePipeConnector connector, Type consumerType, Func<Type, object> objectFactory)
        {
            if (connector == null)
                throw new ArgumentNullException(nameof(connector));
            if (consumerType == null)
                throw new ArgumentNullException(nameof(consumerType));
            if (objectFactory == null)
                throw new ArgumentNullException(nameof(objectFactory));
            if (!consumerType.HasInterface<IConsumer>())
                throw new ArgumentException("The consumer type must implement an IConsumer interface");

            if (_log.IsDebugEnabled)
                _log.DebugFormat("Subscribing Consumer: {0} (by type, using object consumer factory)", consumerType);

            return ConsumerConnectorCache.Connect(connector, consumerType, objectFactory);
        }
        public static UnsubscribeAction SubscribeInterceptingConsumer <TConsumer>([NotNull] this IServiceBus bus,
                                                                                  [NotNull] Action <Action> interceptor)
            where TConsumer : class, IConsumer, new()
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Subscribing Consumer: {0} (using default consumer factory)", typeof(TConsumer));
            }

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

            var interceptingConsumerFactory = new InterceptingConsumerFactory <TConsumer>(delegateConsumerFactory,
                                                                                          interceptor);

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

            return(bus.Configure(x => connector.Connect(x, interceptingConsumerFactory)));
        }
コード例 #6
0
        /// <summary>
        /// Connect a consumer with a consumer type and object factory method for the consumer
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="consumerType"></param>
        /// <param name="objectFactory"></param>
        /// <returns></returns>
        public static ConnectHandle ConnectConsumer(this IConsumePipeConnector connector, Type consumerType, Func <Type, object> objectFactory)
        {
            if (connector == null)
            {
                throw new ArgumentNullException(nameof(connector));
            }
            if (consumerType == null)
            {
                throw new ArgumentNullException(nameof(consumerType));
            }
            if (objectFactory == null)
            {
                throw new ArgumentNullException(nameof(objectFactory));
            }
            if (!consumerType.HasInterface <IConsumer>())
            {
                throw new ArgumentException("The consumer type must implement an IConsumer interface");
            }

            LogContext.Debug?.Log("Connecting Consumer: {ConsumerType} (by type, using object consumer factory)", TypeMetadataCache.GetShortName(consumerType));

            return(ConsumerConnectorCache.Connect(connector, consumerType, objectFactory));
        }
コード例 #7
0
 public static ConnectHandle ConnectConsumer(this IConsumePipeConnector filter, Type consumerType, Func <Type, object> objectFactory)
 {
     return(ConsumerConnectorCache.Connect(filter, consumerType, objectFactory));
 }