@allgemein/eventbus
TypeScript icon, indicating that this package has built-in type declarations

0.14.2 • Public • Published

@allgemein/eventbus

Build Status codecov Dependency Status

Usage

import 'reflect-metadata'
import {Event,EventBus,subscribe} from '@allgemein/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 '@allgemein/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 '@allgemein/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 '@allgemein/eventbus'

let eventBusSettings = {
  name: 'default_redis',
  adapter: 'redis',
  extra: {
    host: '127.0.0.1',
    port: 6379
  }
}

EventBus.$().addConfiguration(eventBusSettings);

Package Sidebar

Install

npm i @allgemein/eventbus

Weekly Downloads

31

Version

0.14.2

License

none

Unpacked Size

240 kB

Total Files

176

Last publish

Collaborators

  • cezaryrk