1.0.16 • Published 7 years ago

abtool-amqp v1.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
7 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

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago