Code Monkey home page Code Monkey logo

simple.esb's Introduction

Simple ESB

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.

Getting Started

Console App

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

AspNet Web App

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

Interfaces

Send Messages

IServiceBus bus = services.GetService<IServiceBus>();
bus.Send(new MyMessage() { Info = "some important stuff" });

Handle Messages

public class MyHandler : IHandle<MyMessage>
{
        public void Handle(MyMessage msg)
        {
            // perform any custom logic here.
        }
}

Sagas and long running tasks

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

Handle exceptions thrown while processing message

public class MyHandler : IHandle<MyMessage>, IHandleAnyException
{
        public void OnHandlerException(object message, Exception exception)
        {
            // any exception will be passed here for custom handling
        }
}

Setup your handler IOC scope

public class SecurityUpdate : IPreviewMessage
{
    public void Peek(object message)
    {
        // perform any preprocessing logic necessary before
        // any of the handlers are called.
    }
}

Motivation

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.

simple.esb's People

Contributors

adamwyss avatar

Watchers

 avatar

Forkers

tuga1975

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.