The atomic processing runtime, helps you to dispatch messages from anywhere (outside the context of a handler), called immediate dispatching.
Configuring immediate dispatching
To set up immediate dispatching, you need the MessageHandler.Runtime.AtomicProcessing extensions package.
PM> Install-Package MessageHandler.Runtime.AtomicProcessing
Integrating into an existing handler runtime configuration
The most common scenario is to add immediate dispatching as a capability to a host integrated handler runtime.
To make this easy, there is an extension method called ImmediateDispatchingPipeline
.
runtimeConfiguration.ImmediateDispatchingPipeline(dispatching =>
{
});
Each invocation of this method will result in a new dispatching pipeline instance.
Once you have a pipeline configuration instance, you can start to configure it.
Route messages
When you want to send a message outside the context of a handler, a route needs to be defined for the destination, you can do this with the RouteMessages
extension method or the RouteMessagesOfType
.
runtimeConfiguration.ImmediateDispatchingPipeline(dispatching =>
{
dispatching.RouteMessagesOfType<SendEmailCommand>(to => {});
});
Route to an azure servicebus queue
You can route messages from a pipeline to an azure service bus queue, using the Queue
extension method on the destination configuration callback, to which you can provide a queue name and service bus connection string.
runtimeConfiguration.ImmediateDispatchingPipeline(dispatching =>
{
dispatching.RouteMessagesOfType<SendEmailCommand>(to => to.Queue("emails", serviceBusConnectionString));
});
Route to an azure servicebus topic
You can route messages from a pipeline to an azure service bus topic, using the Topic
extension method on the destination configuration callback, to which you can provide a topic name and service bus connection string.
runtimeConfiguration.ImmediateDispatchingPipeline(dispatching =>
{
dispatching.RouteMessagesOfType<BookingConfirmed>(to => to.Topic("orderbooking.events", serviceBusConnectionString));
});