Files
discord.js/packages/brokers
Almeida 384e8afa1b chore: bump dependencies (#11539)
* chore(deps): update github-actions

* actions/cache v4 -> v5
* actions/create-github-app-token v2 -> v3
* actions/download-artifact v6 -> v8
* actions/labeler v5 -> v6
* actions/upload-artifact v5 -> v7
* codecov/codecov-action v4 -> v6
* crazy-max/ghaction-github-labeler v5 -> v6
* dessant/lock-threads v5 -> v6
* docker/build-push-action v6 -> v7
* docker/login-action v3 -> v4
* docker/setup-buildx-action v3 -> v4
* pnpm/action-setup v4.1.0 -> v6.0.8

* chore(deps): minor/patch bumps and pnpm v11

* chore(deps): bump lint-staged to v17

* chore(deps): bump commitlint to v21

* chore(deps): bump vercel to v54

* chore(deps): bump vite to v8

* chore(deps): bump chromatic to v17

* chore(deps): bump validate-npm-package-name to v8

* chore(deps): bump uuid to v14

* chore(deps): bump cloudflare to v6

* chore(deps): bump meilisearch to v0.58

* chore(deps): bump fumadocs-mdx to v15

* chore(deps): lockfile

* chore: fixes

* fixup! chore(deps): minor/patch bumps and pnpm v11

* chore(deps): bump vercel to v56

* chore(deps): bump chromatic to v18

* chore: fix format/lint and change prettier range

* chore(deps): bump vitest-websocket-mock to v0.7

* chore(deps): bump cloudflare to v7

* chore(deps): bump meilisearch to v0.59

* chore(deps): bump commander to v15

* chore(deps): bump sharp to v0.35

* chore(deps): bump undici to v8

* chore: lockfile

* fixup! chore(deps): update github-actions

* fix(rest): requested changes

* chore: minor/patch

* chore(deps): bump meilisearch to v0.60

* chore(deps): bump vercel to v57

* fixup! fixup! chore(deps): update github-actions

* chore: revert prettier upgrade

* chore: minor/patch

* chore(deps): bump vercel to v58

* chore(deps): regen lockfile

* chore(deps): undici 8.10.1 and pnpm 11.25

* chore(deps): minor/patch

* fix: lockfile

* chore: more
2026-09-03 10:27:10 +00:00
..
2025-12-08 00:24:29 +00:00
2023-05-03 02:14:22 +02:00
2022-10-13 22:20:36 +02:00
2026-05-23 06:18:45 +00:00
2023-05-03 02:14:22 +02:00
2023-08-24 06:43:23 +02:00
2024-09-02 22:26:25 +03:00
2023-09-30 00:42:43 +00:00
2026-09-03 10:27:10 +00:00
2026-07-17 14:05:28 +01:00


discord.js


Discord server npm version npm downloads Build status Last commit. backers Code coverage

Vercel Cloudflare Workers

About

@discordjs/brokers is a powerful set of message brokers

Installation

Node.js 24.17.0 or newer is required.

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

Example usage

These examples use ES modules.

pub sub

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

// Considering this only pushes events, the group and name are not important.
const broker = new PubSubRedisBroker(new Redis(), { group: 'noop', name: 'noop' });

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

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

const broker = new PubSubRedisBroker(new Redis(), {
	// This is the consumer group name. You should make sure to not re-use this
	// across different applications in your stack, unless you absolutely know
	// what you're doing.
	group: 'subscribers',
	// With the assumption that this service will scale to more than one instance,
	// you MUST ensure `UNIQUE_CONSUMER_ID` is unique across all of them and
	// also deterministic (i.e. if instance-1 restarts, it should still be instance-1)
	name: `consumer-${UNIQUE_CONSUMER_ID}`,
});
broker.on('test', ({ data, ack }) => {
	console.log(data);
	void ack();
});

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

RPC

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

const broker = new RPCRedisBroker(new Redis(), { group: 'noop', name: 'noop' });

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(new Redis(), {
	// Equivalent to the group/name in pubsub, refer to the previous example.
	group: 'responders',
	name: `consumer-${UNIQUE_ID}`,
});
broker.on('testcall', ({ data, ack, reply }) => {
	console.log('responder', data);
	void ack();
	void reply(`Echo: ${data}`);
});

await broker.subscribe(['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.