8.1.0 • Published 2 years ago

@appolo/pubsub v8.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

pubsub module for appolo build 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) {
   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
    }
}
8.1.0

2 years ago

8.0.1

3 years ago

8.0.0

3 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago