Thread-bus is an event bus oriented microservice library.
How it works?
[WIP]
Installation
npm install thread-bus --save
Usage
1. Connect to the AMPQ server
var Thread = ; /** * Specifying options for AMQP server * Note: without options - Thread will use default predefined options (described below). */const options = host: '127.0.0.1' port: 5672; Thread;
2. Open an exchange channel and publish a message
const channelOptions = channel: 'test' // channel name durable: true // durable channels remain active after server restart, default - false; Thread; // We have a possibility to get response from published channel.
As you can see, open
method will create our Producer, which will share specified message with the help of publish
method.
3. Listen an exchange channel
Thread;
Advanced usage
Producer
As was described above, let's imagine that we need to deliver some info for all market's customers. (Holiday's sales, etc. :)). For example we have 2 markets: UK and UA. So, how to share desirable sales? - Just to publish a message to '#:customers' channel. Let's have a look:
// ./index.jsvar Thread = ;var express = ;var app = exports; const config = thread;const PORT = processenvNODE_PORT || 8080;const HOST = processenvNODE_IP || 'localhost' app { appserver = ; // connect to db, etc. // ................... Thread;}; app; // ./services/customers.jsvar Thread = ;const channel = '#:customers'; Thread; module { Thread;};
Consumers
// UK market servicevar Thread = ;var app = exports; app { Thread;}; app; // UK market ./customers.jsvar mailer = ; module { mailer;};
Also the same thing should be done for UA market.