postmaster-general

A simple library for making microservice message calls over a variety of transports.


Keywords
microservice, message bus
License
MIT
Install
npm install postmaster-general@5.1.0

Documentation

postmaster-general

MIT License

Dead-simple, ready-to-use, promise-based Node.js library, for microservice communication over AMQP using rabbot.

This library attempts to provide a simple, ready-to-go microservice message bus by setting defaults on the excellent rabbot library. If you have need of more fine-grained control, you may want to use rabbot directly.

Note: Version 2.0.0 of this library represents a big departure from version 1.0.0. Be sure to check out the examples to make sure you're migrating properly.

Install

npm install --save postmaster-general

Usage

The following snippet showcases basic usage.

const PostmasterGeneral = require('../postmaster-general');

const postmaster = new PostmasterGeneral('pub-sub');

// Start the Postmaster instance.
postmaster.addListener('action:get_greeting', function (message, done) {
	console.log('[action:get_greeting] received');
	return done(null, {
		greeting: 'Hello, ' + message.name
	});
})
	// Add a listener callback.
	.then(() => postmaster.start())
	// Publish a fire-and-forget message.
	.then(() => postmaster.publish('action:get_greeting', {name: 'Bob'}))
	// Publish a message with a callback.
	.then(() => postmaster.request('action:get_greeting', {name: 'Steve'}))
	// Handle the callback.
	.then((res) => {
		console.log(res.greeting);
	});

Wildcards

postmaster-general supports the default AMQP wildcards for topic routes.

License

Licensed under the MIT license.