/// <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); }
private static void Main(string[] args) { HorseMq mq = HorseMqBuilder.Create() .AddClientHandler <ClientHandler>() .AddQueueEventHandler <QueueEventHandler>() .UseJustAllowDeliveryHandler() .Build(); var sampleMessageRouter = mq.AddRouter("SAMPLE-MESSAGE-ROUTER", RouteMethod.Distribute); var sampleMessageQueueBinding = new QueueBinding("sample-message-queue-binding", "SAMPLE-MESSAGE-QUEUE", 1, BindingInteraction.Response); var sampleMessageDirectBinding = new DirectBinding("sample-message-direct-binding", "@type:SAMPLE-MESSAGE-CONSUMER", 2, BindingInteraction.Response, RouteMethod.RoundRobin); sampleMessageRouter.AddBinding(sampleMessageQueueBinding); sampleMessageRouter.AddBinding(sampleMessageDirectBinding); var giveMeGuidRequestRouter = mq.AddRouter("GIVE-ME-REQUEST-ROUTER", RouteMethod.Distribute); var giveMeGuidRequestHandler = new DirectBinding("sample-message-direct-binding", "@name:GIVE-ME-GUID-REQUEST-HANDLER-CONSUMER", 2, BindingInteraction.Response); giveMeGuidRequestRouter.AddBinding(giveMeGuidRequestHandler); HorseServer server = new HorseServer(); server.UseHorseMq(mq); server.Run(15500); }
public async Task Initialize() { HorseMqOptions horseMqOptions = new HorseMqOptions(); horseMqOptions.AutoQueueCreation = true; horseMqOptions.AcknowledgeTimeout = TimeSpan.FromSeconds(90); horseMqOptions.MessageTimeout = TimeSpan.FromSeconds(12); horseMqOptions.Status = QueueStatus.Broadcast; Server = HorseMqBuilder.Create() .AddOptions(horseMqOptions) .AddQueueEventHandler(new TestQueueHandler(this)) .UseDeliveryHandler(d => Task.FromResult <IMessageDeliveryHandler>(new TestDeliveryHandler(this))) .AddClientHandler(new TestClientHandler(this)) .AddAdminAuthorization <TestAdminAuthorization>() .Build(); await Server.CreateQueue("broadcast-a", o => o.Status = QueueStatus.Broadcast); await Server.CreateQueue("push-a", o => o.Status = QueueStatus.Push); await Server.CreateQueue("push-a-cc", o => o.Status = QueueStatus.Push); await Server.CreateQueue("rr-a", o => o.Status = QueueStatus.RoundRobin); await Server.CreateQueue("pull-a", o => o.Status = QueueStatus.Pull); await Server.CreateQueue("cache-a", o => o.Status = QueueStatus.Cache); }
static void Main(string[] args) { HorseMq mq = HorseMqBuilder.Create() .AddOptions(o => o.Status = QueueStatus.Push) .AddClientHandler <ClientHandler>() .AddQueueEventHandler <QueueEventHandler>() .AddPersistentQueues() .UsePersistentDeliveryHandler(DeleteWhen.AfterAcknowledgeReceived, ProducerAckDecision.AfterSaved) .Build(); mq.LoadPersistentQueues(); HorseServer server = new HorseServer(); server.UseHorseMq(mq); server.Run(26222); }
/// <summary> /// Adds persistent queues with customized configuration /// </summary> public static HorseMqBuilder AddPersistentQueues(this HorseMqBuilder builder, Action <DataConfigurationBuilder> cfg) { builder.Server.AddPersistentQueues(cfg); return(builder); }
/// <summary> /// Adds persistent queues with customized configuration /// </summary> public static HorseMqBuilder AddPersistentQueues(this HorseMqBuilder builder) { return(AddPersistentQueues(builder, c => { })); }