PubSub provider for AdonisJS
PubSub provider for AdonisJS
Supported brokers:
- MQTT
- Google PubSub
- Redis
npm install --save adonis-pubsub
Configuration:
node ace configure adonis-pubsub
npm install --save async-mqtt
npm install --save @google-cloud/pubsub
Please configure @adonisjs/redis
(docs) package and set the appropriate redis connection name in config/pubsub.ts
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'))