Napoleon's Pixelated Mugshot

    commons-eventbus
    TypeScript icon, indicating that this package has built-in type declarations

    0.12.2 • Public • Published

    node-commons-eventbus

    Build Status codecov Dependency Status

    Usage

    import 'reflect-metadata'
    import {Event,EventBus,subscribe} from 'commons-eventbus'
     
    // Definition of the exchange object type
    @Event()
    class MySuggestion {
        content:string;
        constructor(content:string){
          this.content = content;
        }
    }
     
    // subscribe to listening for the explicit object type
    class WillListenOnEvent {
     
      @subscribe(MySuggestion)
      letstalk(data:MySuggestion){
        console.log(data.content);
      }
    }
     
    let instance = new WillListenOnEvent()
    EventBus.register(instance);
     
     
    let suggestion = new MySuggestion('blabla');
    EventBus.post(suggestion);
     
    // That's it
     

    Use without annotations:

    import 'reflect-metadata'
    import {Event, subscribe, EventBus, EventBusMeta} from 'commons-eventbus'
     
    // Definition of the exchange object type
    class MySuggestion {
        content:string;
        constructor(content:string){
          this.content = content;
        }
    }
     
    // subscribe to listening for the explicit object type
    class WillListenOnEvent {
     
      letstalk(data:MySuggestion){
        console.log(data.content);
      }
    }
     
    EventBusMeta.$().register({
      type: 'subscribe',
      target: WillListenOnEvent,
      eventClass: MySuggestion,
      methodName: 'letstalk',
      configuration: 'default',
      configurationOptions: null
    });
     
    let instance = new WillListenOnEvent()
    EventBus.register(instance);
     
    let suggestion = new MySuggestion('blabla');
    EventBus.post(suggestion);

    Supported adapter

    • default (Eventemitter)
    • nsq
    • redis

    Configuration

    TODO

    Example configuration for nsq:

    import {EventBus} from 'commons-eventbus'
     
    let eventBusSettings = {
      name: 'default_nsq',
      adapter: 'nsq',
      extra: {
        reader: {
          nsqdTCPAddresses:['localhost:4150'],
          maxInFlight: 100,
          messageTimeout: 30000
        },
        writer:{
          host: '127.0.0.1',
          port: 4150
        }
      }
    }
     
    EventBus.$().addConfiguration(eventBusSettings);
     

    Example configuration for redis:

    import {EventBus} from 'commons-eventbus'
     
    let eventBusSettings = {
      name: 'default_redis',
      adapter: 'redis',
      extra: {
        host: '127.0.0.1',
        port: 6379
      }
    }
     
    EventBus.$().addConfiguration(eventBusSettings);
     

    Install

    npm i commons-eventbus

    DownloadsWeekly Downloads

    28

    Version

    0.12.2

    License

    none

    Unpacked Size

    190 kB

    Total Files

    134

    Last publish

    Collaborators

    • cezaryrk