abtool-amqp

1.0.16 • Public • Published

INSTALLATION

npm install --save oacii-amqp

Setting up a connection

const AMQP = require('abtool-amqp');
const amqp = new AMQP('amqp://localhost:5672');

Usage


request-reply

Process B makes an rpc request to 'add' queue and received by Process A 'add' queue handler. The handler sends a reply by returning an object.

NOTE: message to send and return value must be an object

Process A:

// receive a request
amqp.reply('add', message => {
  return {
    result: message.num1 + message.num2
  };
});

Process B:

// send a request
amqp.request('add', { num1: 10, num2: 15 }).then(rep => {
  console.log(rep.result); // 25
});

send - listen

Make a simple sending and receiving of messages in a 1:1 sender:listener fashion. Process B send a message every 1 second to Process A.

Process A:

// listen to an event
amqp.listen('event', message => {
  console.log(message); // { msg: 'hello from Process B'}
});

Process B:

setInterval(() => {
  amqp.send('event', { msg: 'hello from Process 1' });
}, 1000);

publish - subscribe

Make a simple sending and receiving of messages in a 1:N fashion. Looks similar to send - listen, the difference is one sends a message and any subsribers can receive.

Process A:

amqp.subscribe('broadcast', message => {
  console.log(message); // { msg: 'this is a broadcast message'}
});

Process B:

amqp.subscribe('broadcast', message => {
  console.log(message); // { msg: 'this is a broadcast message'}
});

Process C:

setInterval(() => {
  amqp.publish('broadcast', { msg: 'this is a broadcast message' });
}, 1000);

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.160latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i abtool-amqp

Weekly Downloads

0

Version

1.0.16

License

ISC

Unpacked Size

9.14 kB

Total Files

4

Last publish

Collaborators

  • oacii