public static RabbitMQChannelOptionsBuilder Subscribe(this RabbitMQChannelOptionsBuilder builder, Assembly assembly)
        {
            var subscriberFactories = MessageHandlersLoader.LoadFromAssembly(assembly);

            foreach (var subscriberFactory in subscriberFactories)
            {
                builder.SubscribersFactories.Add(subscriberFactory);
            }

            return(builder);
        }
        public static RabbitMQChannelOptionsBuilder Subscribe(this RabbitMQChannelOptionsBuilder builder, Type handlerType)
        {
            if (!MessageHandlersLoader.IsMessageHandler(handlerType))
            {
                throw new ArgumentException("The supplied type is not a valid message handler.", nameof(handlerType));
            }

            builder.SubscribersFactories.Add(services => MessageHandlersLoader.BuildMessageHandler(services, handlerType));

            return(builder);
        }
Beispiel #3
0
        public static RabbitMQQueueOptionsBuilder Subscribe(this RabbitMQQueueOptionsBuilder builder, Type handlerType)
        {
            if (!MessageHandlersLoader.IsMessageHandler(handlerType))
            {
                throw new ArgumentException("The supplied type is not a valid message handler.", nameof(handlerType));
            }

            builder.OnDeclaredActions.Add((services) => Task.Run(() => {
                var(_, channel, queue) = services.GetContext();

                var startup = services.GetService <LifecycleController>();

                startup.On(
                    LifecycleState.SubscribeQueues,
                    () => channel.Subscribe(MessageHandlersLoader.BuildMessageHandlerToQueueDeclare(queue.Name, services, handlerType))
                    );
            }));

            return(builder);
        }