A simple no frills easy to setup and easy to use enterprise service bus implementation / task queue / saga framework.
I do need a better name.
Add to Program.cs
var host = new SimpleEsbBuilder()
.UseMongoDb("mongodb://localhost:27017", "DatabaseName")
.UseRabbitMq("amqp://guest@localhost:5672")
.RegisterHandlers(typeof(Program).GetTypeInfo().Assembly)
.BlocksWhileRunning()
.Build();
host.Run();
Add to Startup.cs
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSimpleEsb(b =>
{
b.UseRabbitMq("amqp://guest@localhost:5672")
.UseMongoDb("mongodb://localhost:27017", "DatabaseName")
.RegisterHandlers(typeof(Startup).GetTypeInfo().Assembly);
});
}
public void Configure(IApplicationBuilder app)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc()
.UseSimpleEsb();
}
IServiceBus bus = services.GetService<IServiceBus>();
bus.Send(new MyMessage() { Info = "some important stuff" });
public class MyHandler : IHandle<MyMessage>
{
public void Handle(MyMessage msg)
{
// perform any custom logic here.
}
}
public class MySaga : Saga.WithData<MyState>,
IStartedBy<MyMessage>,
IHandle<OtherMessage>
{
public void ConfigureStateDataMapping(mapper)
{
mapper.Map<MyMessage>(m => m.Id).To(d => d.Id);
mapper.Map<OtherMessage>(m => m.Id).To(d => d.Id);
}
public void Handle<MyMessage>()
{
StateData.Running = true;
// perform any logic here
}
public void Handle<OtherMessage>()
{
//
StateData.Running = false;
MarkAsComplete();
}
}
public class MyHandler : IHandle<MyMessage>, IHandleAnyException
{
public void OnHandlerException(object message, Exception exception)
{
// any exception will be passed here for custom handling
}
}
public class SecurityUpdate : IPreviewMessage
{
public void Peek(object message)
{
// perform any preprocessing logic necessary before
// any of the handlers are called.
}
}
I thought it would be a fun project and I would be able to learn a bit.
Other factors:
Nothing available for dotnet core.
Fan of NServiceBus, MassTransit and other ESBs.