/EventTower

message bus implementation with rabbitmq adapter. sends commands/events to the remote processes.

Primary LanguageC#

EventTower

A message bus implementation with functionality sending commands/events to other processes by using RabbitMQ.

Give a star

If you like this repository or you've learned something please give a star ⭐Thanks!

How EventTower works

EventTower

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.

Installation

.NET Core CLI

dotnet add package EventTower

NuGet package manager

Install-Package EventTower

Usage

Setting up an endpoint

Create a messaging endpoint and call Start() method.

 var endpoint = Endpoint.Create("sender");
 endpoint.Start()

Sending commands

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");

Publishing events

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);

Handling Commands/Events

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;
	}
}

Runtime Demo

Runtime demo