@trigo/atrix-pubsub

4.0.2 • Public • Published

Greenkeeper badge NSP Status

atrix-pubsub

** Redis based Pub/Sub integration into atrix microservice framework**

Compatibility

atrix-pubsub < 4.0.0 works with atrix < 6.0.0 atrix-pubsub >= 4.0.0 works with atrix >= 6.0.0

Features

  • Connection setup
  • filename based handler registrations

Installation

# install atrix
npm install -S @trigo/atrix

# install pubsub plugin
npm install -S @trigo/atrix-pubsub

Configuration

handlers/my/fancy^*.js

const Joi = require('joi');

module.exports.descrioption = 'my fancy event handler'
module.exports.schema = joi.object({ ... });
module.exports.handler = async (req, reply, service) => {
	console.log(req)
	// {
	//	path: 'my/fancy/event',
	//	payload: { an: 'event', with: { foo: 'bar' } }
	// 	log: {<logger object>}
	// }

	// publish another message
	await service.publish('other/event', { ... });
}

index.js

'use strict';

const atrix = require('@trigo/atrix');
const path = require('path');

atrix.addService({
	// name of the service
	name: 'pubsub', 
	// plugin configuration
	pubsub: {
		// setup redis connection
		redis: {
			host: 'localhost',
			port: 6379,
		},
		// select which broker to use. allowed: 'redis', 'in-memory' (default)
		broker: 'redis',
		brokerWildcard: '*', // topic path wildcard. allowed : '*', '%' (default and advised)

		// directory containing the handler files
		handlerDir: path.join(__dirname, './handlers'),
	},
});

// start service
await atrix.services.pubsub.start();

// publish message
await atrix.services.pubsub.publish('my/fancy/topic', { an: 'event', with: { foo: 'bar' } });

Readme

Keywords

none

Package Sidebar

Install

npm i @trigo/atrix-pubsub

Weekly Downloads

38

Version

4.0.2

License

MIT

Unpacked Size

228 kB

Total Files

35

Last publish

Collaborators

  • kelkes
  • mdulghier
  • trigo-admin