Pub/Sub messaging using RabbitMQ.
npm install lzo-sapphire OR yarn add lzo-sapphire
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
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');
});
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.
Support this project by becoming a sponsor.
Licensed under the MIT. See the LICENSE file for details.