postmaster-general

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

Usage no npm install needed!

<script type="module">
  import postmasterGeneral from 'https://cdn.skypack.dev/postmaster-general';
</script>

README

# 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.