adonis-pubsub
v1.2.1
Published
PubSub for adonis
Downloads
17
Readme
adonis-pubsub
PubSub provider for AdonisJS
PubSub provider for AdonisJS
Supported brokers:
- MQTT
- Google PubSub
- Redis
Installation
npm install --save adonis-pubsub
Configuration:
node ace configure adonis-pubsub
Per driver configuration
MQTT configuration
npm install --save async-mqtt
Google PubSub configuration
npm install --save @google-cloud/pubsub
Redis configuration
Please configure @adonisjs/redis
(docs) package and set the appropriate redis connection name in config/pubsub.ts
Usage
import Event from '@ioc:Adonis/Core/Event'
import Logger from '@ioc:Adonis/Core/Logger'
import PubSub from '@ioc:Romch007/PubSub'
// Subscribe to topic and listen for message
PubSub.subscribe('example')
Event.on('pubsub:message', ({ topic, message }) => {
Logger.info(`Message from ${topic}: ${message.toString()}`)
})
// Publish message to topic
await PubSub.publish('example', Buffer.from('message data'))