Esempio n. 1
0
        /// <summary>
        /// Implements persistent message delivery handler
        /// </summary>
        /// <param name="builder">Horse MQ Builder</param>
        /// <param name="deleteWhen">Decision when messages are deleted from disk</param>
        /// <param name="producerAckDecision">Decision when producer receives acknowledge</param>
        /// <param name="useRedelivery">True if want to keep redelivery data and send to consumers with message headers</param>
        /// <param name="ackTimeoutPutback">Putback decision when ack message isn't received</param>
        /// <param name="nackPutback">Putback decision when negative ack is received</param>
        /// <returns></returns>
        public static HorseMqBuilder UsePersistentDeliveryHandler(this HorseMqBuilder builder,
                                                                  DeleteWhen deleteWhen,
                                                                  ProducerAckDecision producerAckDecision,
                                                                  bool useRedelivery = false,
                                                                  PutBackDecision ackTimeoutPutback = PutBackDecision.End,
                                                                  PutBackDecision nackPutback       = PutBackDecision.End)
        {
            builder.Server.DeliveryHandlerFactory = async(dh) =>
            {
                DatabaseOptions           databaseOptions = ConfigurationFactory.Builder.CreateOptions(dh.Queue);
                PersistentDeliveryHandler handler         = new PersistentDeliveryHandler(dh.Queue, databaseOptions,
                                                                                          deleteWhen,
                                                                                          producerAckDecision,
                                                                                          useRedelivery,
                                                                                          dh.DeliveryHandlerHeader);

                handler.AckTimeoutPutBack  = ackTimeoutPutback;
                handler.NegativeAckPutBack = nackPutback;

                await handler.Initialize();

                dh.OnAfterCompleted(AfterDeliveryHandlerCreated);
                return(handler);
            };
            return(builder);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates and returns persistent queue
 /// </summary>
 internal static async Task <HorseQueue> CreateQueue(HorseMq mq,
                                                     string queueName,
                                                     DeleteWhen deleteWhen,
                                                     ProducerAckDecision producerAckDecision,
                                                     QueueOptions options)
 {
     return(await mq.CreateQueue(queueName, options, async builder =>
     {
         DatabaseOptions databaseOptions = ConfigurationFactory.Builder.CreateOptions(builder.Queue);
         PersistentDeliveryHandler handler = new PersistentDeliveryHandler(builder.Queue, databaseOptions, deleteWhen, producerAckDecision);
         await handler.Initialize();
         return handler;
     }));
 }
Esempio n. 3
0
        /// <summary>
        /// Creates and initializes new persistent delivery handler for the queue
        /// </summary>
        /// <param name="builder">Delivery handler builder</param>
        /// <param name="deleteWhen">Decision when messages are deleted from disk</param>
        /// <param name="producerAckDecision">Decision when producer receives acknowledge</param>
        /// <param name="useRedelivery">True if want to keep redelivery data and send to consumers with message headers</param>
        /// <param name="key">Definition key for delivery handler. You can manage with that key, how the queue will be reloaded.</param>
        /// <param name="ackTimeoutPutback">Putback decision when ack message isn't received</param>
        /// <param name="nackPutback">Putback decision when negative ack is received</param>
        /// <returns></returns>
        public static async Task <IMessageDeliveryHandler> CreatePersistentDeliveryHandler(this DeliveryHandlerBuilder builder,
                                                                                           DeleteWhen deleteWhen,
                                                                                           ProducerAckDecision producerAckDecision,
                                                                                           bool useRedelivery = false,
                                                                                           PutBackDecision ackTimeoutPutback = PutBackDecision.End,
                                                                                           PutBackDecision nackPutback       = PutBackDecision.End,
                                                                                           string key = "default")
        {
            DatabaseOptions           databaseOptions = ConfigurationFactory.Builder.CreateOptions(builder.Queue);
            PersistentDeliveryHandler handler         = new PersistentDeliveryHandler(builder.Queue, databaseOptions, deleteWhen, producerAckDecision, useRedelivery, key);

            handler.AckTimeoutPutBack  = ackTimeoutPutback;
            handler.NegativeAckPutBack = nackPutback;
            await handler.Initialize();

            builder.OnAfterCompleted(AfterDeliveryHandlerCreated);
            return(handler);
        }