4.0.2 • Published 5 years ago

@trigo/atrix-pubsub v4.0.2

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

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' } });
4.0.2

5 years ago

4.0.1

5 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.0

6 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago