1.0.16 • Published 6 years ago

abtool-amqp v1.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

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);
1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago