Skip to content

Commit

Permalink
Update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhatley authored and bwhatley committed Nov 17, 2017
1 parent 3f00de0 commit fccb86e
Showing 1 changed file with 60 additions and 15 deletions.
75 changes: 60 additions & 15 deletions README.md
@@ -1,12 +1,20 @@
# postmaster-general
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/darklordzw/postmaster-general/blob/master/LICENSE.md) [![Build Status](https://travis-ci.org/darklordzw/postmaster-general.svg?branch=master)](https://travis-ci.org/darklordzw/postmaster-general) [![Coverage Status](https://coveralls.io/repos/github/darklordzw/postmaster-general/badge.svg?branch=master)](https://coveralls.io/github/darklordzw/postmaster-general?branch=master)

Dead-simple, ready-to-use, promise-based Node.js library, for microservice communication over [AMQP][1] using [amqplib][3].
Dead-simple, ready-to-use, promise-based Node.js library for microservice communication over [AMQP][1] using [amqplib][3].

This library attempts to provide a simple, ready-to-go microservice message bus with default settings based on production usage.
## Features
postmaster-general strives to be unopinionated, serving as a thin wrapper around [amqplib][3] that sets some sensible defaults and encourages best-practices, including:

* Dedicated channels for publishing, consuming, and asserting topology.
* Single-purpose listener queues, no mixing messages.
* Built-in RPC support.
* Automatic reconnect on connection failure and channel error.

## Install

Note: This library makes heavy use of the async/await keywords, and requires Node.js 7+.

```sh
npm install --save postmaster-general
```
Expand All @@ -15,33 +23,70 @@ npm install --save postmaster-general
The following snippet showcases basic usage.

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

const postmaster = new PostmasterGeneral('pub-sub');
const postmaster = new PostmasterGeneral({ logLevel: 'debug' });

// Start the Postmaster instance.
postmaster.addListener('action:get_greeting', function (message, done) {
const printGreeting = async (message) => {
console.log('[action:get_greeting] received');
return done(null, {
greeting: 'Hello, ' + message.name
});
})
return { greeting: 'Hello, ' + message.name };
};

// Start the Postmaster instance.
postmaster.connect()
.then(() => postmaster.addListener('action:get_greeting', printGreeting))
// Add a listener callback.
.then(() => postmaster.start())
.then(() => postmaster.startConsuming())
// Publish a fire-and-forget message.
.then(() => postmaster.publish('action:get_greeting', {name: 'Bob'}))
.then(() => postmaster.publish('action:get_greeting', { name: 'Bob' }))
// Publish a message with a callback.
.then(() => postmaster.request('action:get_greeting', {name: 'Steve'}))
.then(() => postmaster.request('action:get_greeting', { name: 'Steve' }))
// Handle the callback.
.then((res) => {
console.log(res.greeting);
})
// Shut everything down.
.then(() => postmaster.shutdown())
.catch((err) => {
console.log(err.message);
})
.then(() => {
process.exit();
});

```

### Wildcards
postmaster-general supports the [default AMQP wildcards for topic routes][4].
### Options
The following options may be overridden in the constructor:

```json
{
"connectRetryDelay": 1000,
"connectRetryLimit": 3,
"consumerPrefetch": 1,
"deadLetterExchange": "postmaster.dlx",
"exchanges": {
"dlx": {
"name": "postmaster.dlx",
"type": "topic"
},
"topic": {
"name": "postmaster.topic",
"type": "topic"
}
},
"handlerTimingResetInterval": 30000,
"heartbeat": 30,
"logLevel": "warn",
"publishRetryDelay": 1000,
"publishRetryLimit": 3,
"queuePrefix": "postmaster.queue",
"removeListenerRetryDelay": 1000,
"removeListenerRetryLimit": 3,
"shutdownTimeout": 30000,
"url": "amqp://guest:guest@localhost:5672"
}
```

## License
Licensed under the [MIT][2] license.
Expand Down

0 comments on commit fccb86e

Please sign in to comment.