Giter Site home page Giter Site logo

liuyong2013 / eventbus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from feiniubus/eventbus

0.0 0.0 0.0 271 KB

EventBus is a .Net Standard library to achieve eventually consistent in distributed architectures system like SOA,MicroService. It is lightweight,easy to use and efficiently.

License: MIT License

C# 100.00%

eventbus's Introduction

EventBus

Branch Pipeline
master Build statusBuild Status
release Build statusBuild status
milestone/1.0.0 Build statusBuild Status

OverView

EventBus is a .Net Standard library to achieve eventually consistent in distributed architectures system like SOA,MicroService. It is lightweight,easy to use and efficiently.

Getting Started

Step 1 : Configure EventBus Options

*** Add following code after services.AddDbContext in StartUp.cs ***

services.AddEventBus(options =>
{
  // using EntityFramework
  options.UseEntityframework<**Your DbContext Type**>();
  
  // OR using Ado.NET 
  options.UseMySQL(**Database connection string**)
  
  // using RabbitMQ
  options.UseRabbitMQ(rabbit =>
  {
    rabbit.HostName = "**Your hostname of RabbitMQ**";
    rabbit.UserName = "**Your username if needed**";
    rabbit.Password = "**Your password if needed**";
  });
 });

*** Add following codes in Configure scope of StartUp.cs ***

app.UseEventBus();

Step 2 : Publish Event

  • Inject IEventPublisher in constructor like .ctor(IEventPublisher eventPublisher)
  • Begin a transaction
    • using EntityFramework
using(var transaction = dbContext.Database.BeginTransaction)
{
  //TODO:Businesses codes
  
  //Publish Event
  await _eventPublisher.PrepareAsync(/*RouteKey*/, /*Content Object*/, /*MetaData Object*/);
  
  //Commit transaction
  transaction.Commit();
  
  //Confirm Published Event.The event message won't publish untill invoked **IEventPublisher.ConfirmAsync()**
  //And you can decide when the event message be confirmed all by your self.
  await _eventPublisher.ConfirmAsync();
  
  //Or you can just rollback these messages when exception was thrown.
  await _eventPublisher.RollbackAsync();
}
  • using Ado.NET
 IDbConnection dbConnection; /*Open your database connection.*/
IDbTransaction dbTransaction = dbConnection.BeginTransaction();

//TODO:Businesses codes

//Publish Event
await _eventPublisher.PrepareAsync(/*RouteKey*/, /*Content Object*/, /*MetaData Object*/,dbConnection,dbTransaction);

//Commit transaction
dbTransaction.Commit();
dbConnection.Close();

//Confirm Published Event.The event message won't publish untill invoked **IEventPublisher.ConfirmAsync()**
//And you can decide when the event message should be confirmed all by your self.
await _eventPublisher.ConfirmAsync();

//Or you can just rollback these messages when exception was thrown.
await _eventPublisher.RollbackAsync();

step 3 : Dead letter callback handler

  • Declare a callback handler class implemented IFailureHandler
  • Register callback handle in AddEventBus scope
options.UseFailureHandle(failure =>
{
 failure.RegisterFailureCallback(/*RouteKey*/, /*Type of your deadletter callback handler*/);
});

Step 4 : Consumer callback handler

  • Declare a callback handler class implemented ISubscribeCallbackHandler
  • Register callback handle in StartUp.cs
services.AddSub(options =>
{
  options.ConsumerClientCount = 1;
  options.DefaultGroup = "/*Default Group Name*/";
  // Use default group
  options.RegisterCallback(/*RouteKey*/, /*Type of your callback handler*/);
  // Use specialized group
  options.RegisterCallback(/*RouteKey*/,/*Group Name*/ /*Type of your callback handler*/);
 });

eventbus's People

Contributors

ah-its-andy avatar gotoxu avatar hongyanshen avatar

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.