예제 #1
0
        public static RabbitMQQueueOptionsBuilder OnDeclare(this RabbitMQQueueOptionsBuilder builder, Func <IRabbitMQQueue, Task> action)
        {
            builder.OnDeclaredActions.Add(async(services) => {
                var queue = services.GetService <IRabbitMQQueue>();

                await action(queue);
            });

            return(builder);
        }
예제 #2
0
        public static RabbitMQQueueOptionsBuilder Bind(this RabbitMQQueueOptionsBuilder builder, string exchange, string routingKey, IDictionary <string, object> arguments = null)
        {
            builder.OnDeclaredActions.Add((services) => Task.Run(() => {
                var(_, channel, queue) = services.GetContext();

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

                startup.On(LifecycleState.BindEntities, () => Task.Run(() => {
                    channel.Model.QueueBind(queue.Name, exchange, routingKey, arguments);
                }));
            }));

            return(builder);
        }
        public static RabbitMQChannelOptionsBuilder DeclareQueue(
            this RabbitMQChannelOptionsBuilder builder,
            string queue    = "",
            bool durable    = false,
            bool exclusive  = true,
            bool autoDelete = true,
            IDictionary <string, object> arguments             = null,
            Action <RabbitMQQueueOptionsBuilder> optionsAction = null)
        {
            builder.QueuesOptionsFactories.Add(() =>
            {
                var queueBuilder = new RabbitMQQueueOptionsBuilder(queue, durable, exclusive, autoDelete, arguments);
                optionsAction?.Invoke(queueBuilder);
                return(queueBuilder.Build());
            });

            return(builder);
        }
예제 #4
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);
        }
예제 #5
0
        public static RabbitMQQueueOptionsBuilder Subscribe(this RabbitMQQueueOptionsBuilder builder, AcknowledgeMode acknowledgeMode, ExceptionMode exceptionMode, Func <RabbitMQDelivery, Task> handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

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

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

                startup.On(
                    LifecycleState.SubscribeQueues,
                    () => channel.Subscribe(new QueueConsumerSubscriber(queue.Name, acknowledgeMode, exceptionMode, new LambdaMessageHandler(handler), contextAccessor))
                    );
            }));

            return(builder);
        }
예제 #6
0
 public static RabbitMQQueueOptionsBuilder Subscribe(this RabbitMQQueueOptionsBuilder builder, AcknowledgeMode acknowledgeMode, Func <RabbitMQDelivery, Task> handler)
 => builder.Subscribe(acknowledgeMode, ExceptionModeAttribute.DefaultMode, handler);
예제 #7
0
 public static RabbitMQQueueOptionsBuilder Subscribe <THandler>(this RabbitMQQueueOptionsBuilder builder)
     where THandler : IMessageHandler <RabbitMQDelivery>
 => builder.Subscribe(typeof(THandler));