Skip to content

A simple library for making synchronous and asynchronous microservice calls using Node.js over AMQP

License

Notifications You must be signed in to change notification settings

darklordzw/postmaster-general

Repository files navigation

postmaster-general

MIT License Build Status Coverage Status

Simple, promise-based Node.js library for microservice communication over a variety of transport protocols.

Transport Plugins

postmaster-general functions using a variety of transport plugins that should be installed as peer-dependencies.

Install

npm install --save postmaster-general

Usage

The following snippet showcases basic usage.

const PostmasterGeneral = require('postmaster-general');
const HTTPTransport = require('postmaster-general-http-transport');

const transport = new HTTPTransport();
const postmaster = new PostmasterGeneral({
	requestTransport: transport,
	publishTransport: transport
});

const printGreeting = (message) => {
	console.log('[action:get_greeting] received');
	return Promise.resolve({ greeting: 'Hello, ' + message.name });
};

// Start the Postmaster instance.
postmaster.connect()
	.then(() => postmaster.addRequestListener('action:get_greeting', printGreeting))
	.then(() => postmaster.listen())
	.then(() => postmaster.request('action:get_greeting', { name: 'Steve' }))
	.then((res) => {
		// Handle the response.
		console.log(res.greeting);
	})
	.then(() => postmaster.disconnect())
	.catch((err) => {
		console.log(err.message);
	});

Options

See the "docs" folder for documentation.

License

Licensed under the MIT license.

About

A simple library for making synchronous and asynchronous microservice calls using Node.js over AMQP

Resources

License

Stars

Watchers

Forks

Packages

No packages published