0.9.3 • Published 2 years ago

@spectacles/brokers v0.9.3

Weekly downloads
59
License
ISC
Repository
github
Last release
2 years ago

Spectacles brokers

A unified event publishing API to allow simple and powerful communication between services. Available brokers:

  • AMQP - connects to an AMQP server
  • Local - keeps events on a local event emitter
  • Redis - connects to a Redis v5 server
  • IPC - connects multiple node processes using native IPC sockets

How to use

const { Amqp } = require('@spectacles/brokers');
const broker = new Amqp('some group name');

(async () => {
  broker.on('hello', (data, { ack, reply }) => {
    ack();
    reply(`hello ${data}`);
  });

  broker.on('foo', (data, { ack }) => {
    ack();
    console.log(data);
  });

  await broker.connect('localhost');
  await broker.subscribe([
    'hello',
    'foo',
  ]);

  console.log(await broker.call('hello', 'world')); // hello world
  await broker.publish('foo', 'bar'); // bar
})();

Obviously this is intended for use across multiple separate applications, where you publish in one app and subscribe in another.

Note: When publishing data on AMQP, you should call Amqp#createQueue(event) for every event you intend to publish. This will create the queue and ensure your events aren't dropped.

0.9.3

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

2 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago