discord.js/packages/brokers
2023-09-30 00:42:43 +00:00
..
__tests__ build: refactor linting 2023-08-22 09:40:11 +02:00
docs chore: refactor workspace 2023-05-03 02:14:22 +02:00
scripts feat: @discordjs/brokers (#8548) 2022-10-13 22:20:36 +02:00
src build: refactor linting 2023-08-22 09:40:11 +02:00
.cliff-jumperrc.json feat: @discordjs/brokers (#8548) 2022-10-13 22:20:36 +02:00
.gitignore chore: refactor workspace 2023-05-03 02:14:22 +02:00
.lintstagedrc.js feat: @discordjs/brokers (#8548) 2022-10-13 22:20:36 +02:00
.prettierignore build: ignores/swap/concurrency 2023-08-24 21:58:34 +02:00
.prettierrc.js build: refactor linting setup 2023-08-24 06:43:23 +02:00
api-extractor-docs.json docs: generate static imports for types with api-extractor 2023-04-17 19:08:01 +02:00
api-extractor.json feat(website): add support for source file links (#9048) 2023-01-12 13:49:11 +01:00
CHANGELOG.md chore(brokers): release @discordjs/brokers@0.2.2 2023-08-17 21:34:23 +02:00
cliff.toml build: git-cliff config 2023-04-02 01:55:39 +02:00
LICENSE chore: update license files (#9862) 2023-09-30 00:42:43 +00:00
package.json build: pnpm (#9806) 2023-08-27 20:24:03 +02:00
README.md docs: Update Node.js requirement to 16.11.0 (#9764) 2023-08-13 19:49:33 +00:00
tsconfig.docs.json chore: config overhaul 2023-08-22 01:33:47 +02:00
tsconfig.eslint.json build: refactor linting setup 2023-08-24 06:43:23 +02:00
tsconfig.json chore: config overhaul 2023-08-22 01:33:47 +02:00
tsup.config.ts chore: switch tsup config to typescript (#9057) 2023-01-13 09:44:56 +00:00


discord.js


Discord server npm version npm downloads Build status Code coverage

Vercel Cloudflare Workers

About

@discordjs/brokers is a powerful set of message brokers

Installation

Node.js 16.11.0 or newer is required.

npm install @discordjs/brokers
yarn add @discordjs/brokers
pnpm add @discordjs/brokers

Example usage

pub sub

// publisher.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker({ redisClient: new Redis() });

await broker.publish('test', 'Hello World!');
await broker.destroy();

// subscriber.js
import { PubSubRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new PubSubRedisBroker({ redisClient: new Redis() });
broker.on('test', ({ data, ack }) => {
	console.log(data);
	void ack();
});

await broker.subscribe('subscribers', ['test']);

RPC

// caller.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });

console.log(await broker.call('testcall', 'Hello World!'));
await broker.destroy();

// responder.js
import { RPCRedisBroker } from '@discordjs/brokers';
import Redis from 'ioredis';

const broker = new RPCRedisBroker({ redisClient: new Redis() });
broker.on('testcall', ({ data, ack, reply }) => {
	console.log('responder', data);
	void ack();
	void reply(`Echo: ${data}`);
});

await broker.subscribe('responders', ['testcall']);

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the documentation.
See the contribution guide if you'd like to submit a PR.

Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official discord.js Server.