-
Notifications
You must be signed in to change notification settings - Fork 753
Support for Delayed Messages Plugin
The RabbitMQ Delayed Message Plugin is still in the experimental phase.
You use it at your own risk.
The RabbitMQ Delayed Message Plugin adds a new exchange type to RabbitMQ which allows to delay message delivery.
EasyNetQ provides support for using that exchange by defining a new scheduler type: DelayedExchangeScheduler
.
This allows you to use the same Future Publish interface as before. The below example shows how to publish a message which will get delivered within three months from now:
For EasyNetQ v8.x:
var serviceCollection = new ServiceCollection();
serviceCollection.AddEasyNetQ("host=localhost").UseDelayedExchangeScheduler();
using var provider = serviceCollection.BuildServiceProvider();
var bus = provider.GetRequiredService<IBus>();
var followUpCallMessage = new FollowUpCallMessage( .. );
bus.Scheduler.FuturePublish(DateTime.UtcNow.AddMonths(3), followUpCallMessage);
The UseDelayedExchangeScheduler
method instructs EasyNetQ to use a new scheduler that supports Delayed Message Exchanges. Then, retrieve the bus instance from the DI service provider. Next, the message is created and published with a delivery time set to three months. Note that FuturePublish
uses UTC time.
For EasyNetQ v7.x:
bus = RabbitHutch.CreateBus("host=localhost", x => x.EnableDelayedExchangeScheduler());
var followUpCallMessage = new FollowUpCallMessage( .. );
bus.Scheduler.FuturePublish(DateTime.UtcNow.AddMonths(3), followUpCallMessage);
The first line instructs EasyNetQ to use a new scheduler that supports Delayed Message Exchanges. Next, the message is created and published with delivery time set to three months. Note that FuturePublish
uses UTC time.
DelayedExchangeScheduler requires Delayed Message Plugin to be installed.
Delayed Message Plugin can be found on Community Plugins page. Download the corresponding .ez file for your RabbitMQ installation, copy it into RabbitMQ's plugin folder and then enable it by running the following command:
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
The plugin requires RabbitMQ version 3.4 or newer.
When you call bus.Scheduler.FuturePublish(...), EasyNetQ automatically creates new x-delayed-message
exchange along with normal exchange and binds them together. The message is published on the delayed exchange which will store the message until the time comes to deliver it. At that point, the message is routed to normal exchange and from there to bound queue(s).
When you call Publish(...) method, the messages are published to normal exchange which prevents any performance degradation related to using new x-delayed-message
exchange.
The delayed exchange persists messages using Mnesia. That prevents messages loss in case of server downtime. Once the server restores, all eligible messages will be delivered on schedule.
- Quick Start
- Introduction
- A Note on Versioning
- Installing EasyNetQ
- Connecting to RabbitMQ
- Connecting with SSL
- Logging
- Logging v8.x
- Publish
- Subscribe
- Request Response
- Send Receive
- Topic Based Routing
- Controlling Queue names
- Polymorphic Publish and Subscribe
- Versioning Messages
- Publisher Confirms
- Scheduling Events with Future Publish
- Support for Delayed Messages Plugin
- Auto Subscriber
- Auto Subscriber v8.x
- Error Conditions
- Re Submitting Error Messages With EasyNetQ.Hosepipe
- The Advanced API
- Cluster Support
- Wiring up EasyNetQ with TopShelf and Windsor
- Replacing EasyNetQ Components
- Using Alternative DI Containers
- Enable Legacy Conventions