A message bus implementation with functionality sending commands/events to other processes by using RabbitMQ.
If you like this repository or you've learned something please give a star ⭐Thanks!
EventTower uses RabbitMQ.Client package to establish a connection to the given RabbitMQ server. Uses an abstraction layer called 'RabbitMQAdapter' to publishing/subscribing logic. For more information take a look at my blog post.
.NET Core CLI
dotnet add package EventTower
NuGet package manager
Install-Package EventTower
Create a messaging endpoint and call Start() method.
var endpoint = Endpoint.Create("sender");
endpoint.Start()
Create a command class implements the EventTower.ICommand
interface and use Send()
method to send the command to the destination endpoint.
var command = new CreateOrderCommand();
endpoint.Send(command, "destinationEndpoint");
Create an event class implements the EventTower.IEvent
interface and Use Publish()
method to publish the event to all destinations.
var @event = new CustomerEmailChanged();
endpoint.Publish(@event);
Create a handler class that implements IMessageHandler<T>
interface. The generic parameter must be ICommand
or IEvent
. A sample event handler is shown below. Commands are handles in the same way.
public class EventHandler :
IMessageHandler<CustomerEmailChanged>
{
public Task Handle(CustomerEmailChanged message)
{
Console.WriteLine("An CustomerEmailChanged event received. Content: {0}", JsonConvert.SerializeObject(message));
return Task.CompletedTask;
}
}