-
Enterprise Service Bus libraries for .NET – Rebus
One in a series of posts giving a quick overview of ESB libraries for .NET
Rebus describes itself as "a lean service bus implementation for .NET".
https://github.com/rebus-org/Rebus
Messages
POCO classes
Publishing
Use an instance of
IBus
to publish.activator
is an implementation ofIHandlerActivator
- eitherBuiltinHandlerActivator
or an adapter class for your particular IoC container.activator.Bus.Publish(new DateTimeMessage(DateTime.Now)).Wait();
Subscribing
Handlers implement
IHandleMessages<T>
public class PrintDateTime : IHandleMessages<DateTime> { public async Task Handle(DateTime currentDateTime) { Console.WriteLine("The time is {0}", currentDateTime); } }
And register a subscription
activator.Bus.Subscribe<StringMessage>().Wait();
-
Enterprise Service Bus libraries for .NET – Shuttle ESB
One in a series of posts giving a quick overview of ESB libraries for .NET
Shuttle ESB describes itself as a "free .NET open-source enterprise service bus". It supports a good range of transports and integrates with a number of IoC containers.
https://github.com/Shuttle/shuttle-esb
Messages
A POCO class
Publishing
Publish using
IServiceBus
. You'll also make use of static methods from theServiceBus
class.using (var bus = ServiceBus.Create(resolver).Start()) { bus.Publish(new MemberRegisteredEvent { UserName = "Mr Resistor" }); }
Subscribing
A handler implements
IMessageHandler
public class MemberRegisteredHandler : IMessageHandler<MemberRegisteredEvent> { public void ProcessMessage(IHandlerContext<MemberRegisteredEvent> context)
{ Console.WriteLine(); Console.WriteLine("[EVENT RECEIVED] : user name = ‘{0}’", context.Message.UserName); Console.WriteLine(); } }
You also need to tell the subscription manager that you want to subscribe to a particular event.
resolver
is a wrapper class for your specific container.resolver.Resolve<ISubscriptionManager>().Subscribe<MemberRegisteredEvent>();
-
Enterprise Service Bus libraries for .NET – Nimbus
One in a series of posts giving a quick overview of ESB libraries for .NET
Nimbus primarily supports the Azure Service Bus as a transport, so if your application is going to run in Azure, then this could be a good choice.
https://github.com/NimbusAPI/Nimbus/wiki/Publishing-an-Event-on-the-Bus
Messages
Event messages should implement
IBusEvent
Publishing
Publish with an instance of
IBus
_bus.Publish(new NewOrderReceived {CustomerName = "Ricky Bobby"});
Subscribing
Handle events by implementing
IHandleMulticastEvent
public class ListenForNewOrders : IHandleMulticastEvent { public async Task Handle(NewOrderReceived busEvent) { Console.WriteLine("I heard about a new order from " + busEvent.CustomerName); //Do more stuff } }