@appolo/pubsub

8.1.0 • Public • Published

pubsub module for appolo build with ioredis

Installation

npm i @appolo/pubsub

Options

key Description Type Default
id PubSubProvider injection id string pubSubProvider
auto true to auto initialize pubsub listen events boolean true
connection redis connection string string null

in config/modules/all.ts

import {PubSubModule} from '@appolo/pubsub';

export = async function (app: App) {
   await app.module(new PubSubModule({redis:"redis://redis-connection-string"}));
}

Usage

Publisher

import {define, singleton} from 'appolo'
import {publisher} from "@appolo/pubsub";

@define()
@singleton()
export class SomePublisher {

    @publisher("test")
    async publish(data: any): Promise<any> {
        return data
    }
}

Or with PubSubProvider

@define()
@singleton()
export class SomePublisher {

    inject() pubSubProvider:PubSubProvider

    async publish(data:any): Promise<any> {
        return this.pubSubProvider.publish("test",data)
    }
}

Handler

import {define, singleton} from 'appolo'
import {handler} from "@appolo/pubsub";

@define()
@singleton()
export class SomeHandler {

    @handler("test")
    handle(data: any) {
       //do something
    }

    @handler("someName")
    handle(data: any) {
        //do some thing
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @appolo/pubsub

Weekly Downloads

14

Version

8.1.0

License

MIT

Unpacked Size

49.6 kB

Total Files

38

Last publish

Collaborators

  • saar120
  • shmoop207