A highly flexible and free .NET open-source enterprise service bus.
There is extensive documentation on our site and you can make use of the samples to get you going.
Start a new Console Application project and select a Shuttle.Esb queue implementation from the [supported queues]({{ site.baseurl }}/packages/#queues):
Install-Package Shuttle.Esb.Msmq
Now we'll need select one of the supported containers:
Install-Package Shuttle.Core.Autofac
We'll also need to host our endpoint using the service host:
Install-Package Shuttle.Core.ServiceHost
Next we'll implement our endpoint in order to start listening on our queue:
internal class Program
{
private static void Main()
{
ServiceHost.Run<Host>();
}
}
public class Host : IServiceHost
{
private IServiceBus _bus;
public void Start()
{
var containerBuilder = new ContainerBuilder();
var registry = new AutofacComponentRegistry(containerBuilder);
ServiceBus.Register(registry);
var resolver = new AutofacComponentResolver(containerBuilder.Build());
_bus = ServiceBus.Create(resolver).Start();
}
public void Stop()
{
_bus.Dispose();
}
}
A bit of configuration is going to be needed to help things along:
<configuration>
<configSections>
<section name="serviceBus" type="Shuttle.Esb.ServiceBusSection, Shuttle.Esb"/>
</configSections>
<serviceBus>
<inbox
workQueueUri="msmq://./shuttle-server-work"
deferredQueueUri="msmq://./shuttle-server-deferred"
errorQueueUri="msmq://./shuttle-error" />
</serviceBus>
</configuration>
using (var bus = ServiceBus.Create(resolver).Start())
{
bus.Send(new RegisterMemberCommand
{
UserName = "Mr Resistor",
EMailAddress = "ohm@resistor.domain"
});
}
using (var bus = ServiceBus.Create(resolver).Start())
{
bus.Publish(new MemberRegisteredEvent
{
UserName = "Mr Resistor"
});
}
resolver.Resolve<ISubscriptionManager>().Subscribe<MemberRegisteredEvent>();
public class RegisterMemberHandler : IMessageHandler<RegisterMemberCommand>
{
public void ProcessMessage(IHandlerContext<RegisterMemberCommand> context)
{
Console.WriteLine();
Console.WriteLine("[MEMBER REGISTERED] : user name = '{0}'", context.Message.UserName);
Console.WriteLine();
context.Publish(new MemberRegisteredEvent
{
UserName = context.Message.UserName
});
}
}
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();
}
}