Code Monkey home page Code Monkey logo

abp.remoteeventbus's Introduction

Abp.RemoteEventBus

What’s this?

受到Abp事件总线的灵感而开发的一个分布式的事件总线,可以跨应用触发事件。基于发布/订阅模式,消息的传递可以通过redis,rabbitmq,kafka等实现。你还能非常容易的实现你自己的方式,通过实现指定接口。支持控制台和web应用。

A distributed event bus, inspired by the Abp event bus, can trigger events across applications. Based on publish / subscribe mode, the message can be passed through redis, rabbitmq, kafka and so on. You can also very easily implement your own way by implementing the specified interface. Support in console and web applications.

How to use?

Publish

    var eventDate = new RemoteEventData("Type_Test")
        {
            Data ={["playload"]=DateTime.Now}
        };
    remoteEventBus.Publish("Topic_Test", eventDate);

Subscribe

    [RemoteEventHandler(ForType = "Type_Test", ForTopic = "Topic_Test")]
    public class RemoteEventHandler : IRemoteEventHandler, ITransientDependency
    {
        public void HandleEvent(RemoteEventArgs eventArgs)
        {
            Logger.Info("receive " + eventArgs.EventData.Data["playload"]);
        }
    }

Configuration

Use kafka

    [DependsOn(typeof(AbpRemoteEventBusKafkaModule))]
    public class DemoModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(DemoModule).GetAssembly());
        }

        public override void PostInitialize()
        {
            // use kafka
            Configuration.Modules.RemoteEventBus().UseKafka().Configure((setting) =>
            {
                setting.Properties.Add("bootstrap.servers", "192.168.188.142:9092");
                setting.Properties.Add("group.id", "App-Test");
            });
            
            // enable auto subscribe
            // will scan class which use RemoteEventHandlerAttribute and auto subscribe topic base the attribute info
            Configuration.Modules.RemoteEventBus().AutoSubscribe();
        }
    }

Use RabbitMQ

    [DependsOn(typeof(AbpRemoteEventBusRabbitMQModule))]
    public class DemoModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(DemoModule).GetAssembly());
        }

        public override void PostInitialize()
        {
            // use rabbitmq
            Configuration.Modules.RemoteEventBus().UseRabbitMQ().Configure(setting =>
            {
                //setting.Url = "amqp://guest:[email protected]:5672/";
            });
            
            // enable auto subscribe
            // will scan class which use RemoteEventHandlerAttribute and auto subscribe topic base the attribute info
            Configuration.Modules.RemoteEventBus().AutoSubscribe();
        }
    }

Use Redis

    [DependsOn(typeof(AbpRemoteEventBusRedisModule))]
    public class DemoModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(DemoModule).GetAssembly());
        }

        public override void PostInitialize()
        {   
            // use redis
            Configuration.Modules.RemoteEventBus().UseRedis().Configure((setting) =>
            {
                setting.Server = "127.0.0.1:6379";
            });
            
            // enable auto subscribe
            // will scan class which use RemoteEventHandlerAttribute and auto subscribe topic base the attribute info
            Configuration.Modules.RemoteEventBus().AutoSubscribe();
        }
    }

Demo

See Abp.RemoteEventBus.RabbitMQ.Test

How it work?

Here

abp.remoteeventbus's People

Contributors

jerrytang67 avatar wuyi6216 avatar

Stargazers

 avatar

Watchers

 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.