Skip to content

Lack-Zillions-Over/sapphire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LZO: Sapphire

Pub/Sub messaging using RabbitMQ.

Sponsor Commitizen friendly TypeScript version Node.js version MIT Build Status - GitHub Actions

Installation

npm install lzo-sapphire OR yarn add lzo-sapphire

Configuration

Please input the credentials of your RabbitMQ server in the .env file.

See the example in the .env.example file.

RABBITMQ_URL="amqp://admin:admin@rabbitmq:5672"
RABBITMQ_PORT=5672

Usage

import { sapphire } from 'lzo-sapphire';

Sapphire.subscribe(
  (value) => console.log(typeof value, value), // object, { name: 'John Doe' }
  'testing',
);

setTimeout(() => {
  Sapphire.publish({ name: 'John Doe' }, 'testing');
});

API

Sapphire.publish<T>(value: T, ...channels: string[]): Promise<string[]>

Publishes a message to a channel or multiple channels.

Sapphire.subscribe<T>(callback: (message: T) => Promise<void>, ...channels: string[]): Promise<void>

Subscribes to a channel or multiple channels.

Backers & Sponsors

Support this project by becoming a sponsor.

License

Licensed under the MIT. See the LICENSE file for details.