-
Notifications
You must be signed in to change notification settings - Fork 84
Publishing an Event on the Bus
In a distributed system, the different components need to react to significant business events that take place that are raised by other components of the system.
Events in your architecture might be things like OrderConfirmed, CustomerCreated or AccountSuspended. These events may be of interest to many other parts of your system.
This pattern is called Publish / Subscriber, sometimes shortened to PubSub. In this pattern we have a Publisher of the event, and multiple applications that Subscribe to these events and act on them.
To raise or publish an event with Nimbus we implement the event class as an IBusEvent and publish it using the bus.Publish method.
_bus.Publish(new NewOrderReceived {CustomerName = "Ricky Bobby"});
To handle the event, we create a class which implements the IHandleMulticastEvent interface.
public class ListenForNewOrders : IHandleMulticastEvent<NewOrderReceived>
{
public async Task Handle(NewOrderReceived busEvent)
{
Console.WriteLine("I heard about a new order from " + busEvent.CustomerName);
//Do more stuff
}
}
We can have multiple applications subscribing to these events, and multiple instances of each application. Remember how we set up an Application name and an instance name in our bus configuration? We make sure that each of these gets a copy of the message because we create a subscriber queue for each instance.
Azure Service Bus
Windows Service Bus
Redis
In Process
Configuring Nimbus With Autofac
Configuring Nimbus With Windsor
Configuring Nimbus With Ninject
Sending a Command on the Bus
Publishing an Event on the Bus
Request Response
Multicast Request Response
Multicast Request Response - take First
Large Message Support