PubSub

pubsub module built with ioredis

Installation#

npm i @appolo/pubsub

Options#

keyDescriptionTypeDefault
idPubSubProvider injection idstringpubSubProvider
autotrue to auto initialize pubsub listen eventsbooleantrue
connectionredis connection stringstringnull

in config/modules/all.ts

import {PubSubModule} from '@appolo/pubsub';
export = async function (app: App) {
app.module.use(PubSubModule.for({
connection:"redis://redis-connection-string"
}));
}

Usage#

Publisher#

import {define, singleton} from '@appolo/inject'
import {PubSubProvider} from "@appolo/pubsub";
@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/inject'
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
}
}