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 the ServiceBus 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>();