@devmastery/pubsub
v0.0.1
Published
A lightweight pub/sub wrapper around amqplib that only offers two basic functions: publish and subscribe.
Downloads
4
Readme
@devmastery/pubsub
A lightweight pub/sub wrapper around amqplib that only offers two basic functions: publish
and subscribe
.
Installation
npm install @devmastery/pubsub --save
Configuration
The settings for the amqp cluster are pulled from evironment variables. Please make sure these variables are set and available wherever you use this library. See below for mapping:
{
protocol: process.env.DM_MQ_PROTOCOL,
hostname: process.env.DM_MQ_HOSTNAME,
port: process.env.DM_MQ_PORT,
username: process.env.DM_MQ_USERNAME,
password: process.env.DM_MQ_PASSWORD,
locale: process.env.DM_MQ_LOCALE,
frameMax: process.env.DM_MQ_FRAME_MAX,
heartbeat: process.env.DM_MQ_HEARTBEAT,
vhost: process.env.DM_MQ_VHOST
}
Example
// publisher
const { publish } = require('@devmastery/pubsub')
publish({ message: 'An example message', topic: 'pubsub-demo' })
// subscriber
const { subscribe } = require('@devmastery/pubsub')
subscribe({
topic: 'pubsub-demo',
subscription: 'examples',
onMessage: ({ content }) => {
console.log(`Received: ${content.toString()}`)
}
})