@spectacles/brokers
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @spectacles/brokers

Weekly Downloads

22

Version

0.9.3

License

ISC

Unpacked Size

94.7 kB

Total Files

34

Last publish

Collaborators

  • appellation
  • hackzzila
  • nomsy