mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 01:34:43 +12:00
* fix(BaseRedis): remove listeners on destroy and stop pooling when no subscription * refactor(BaseRedis): group as constructor param and cleanup subscribers * fix(BaseRedis): remove listeners on destroy and stop pooling when no subscription * refactor(BaseRedis): group as constructor param and cleanup subscribers * chore(RPCRedis): group * Update packages/brokers/src/brokers/Broker.ts * Update packages/brokers/src/brokers/Broker.ts * Update packages/brokers/src/brokers/redis/BaseRedis.ts Removed `removeAllListeners` from destroy * chore(BaseRedis): destroy unsubscribe spread array --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> |
||
---|---|---|
.. | ||
__tests__ | ||
docs | ||
scripts | ||
src | ||
.cliff-jumperrc.json | ||
.gitignore | ||
.lintstagedrc.js | ||
.prettierignore | ||
.prettierrc.js | ||
api-extractor.json | ||
CHANGELOG.md | ||
cliff.toml | ||
LICENSE | ||
package.json | ||
README.md | ||
tsconfig.docs.json | ||
tsconfig.eslint.json | ||
tsconfig.json | ||
tsup.config.ts |
About
@discordjs/brokers
is a powerful set of message brokers
Installation
Node.js 18 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(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(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(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(new Redis());
broker.on('testcall', ({ data, ack, reply }) => {
console.log('responder', data);
void ack();
void reply(`Echo: ${data}`);
});
await broker.subscribe('responders', ['testcall']);
Links
- Website (source)
- Documentation
- Guide (source) Also see the v13 to v14 Update Guide, which includes updated and removed items from the library.
- discord.js Discord server
- Discord API Discord server
- GitHub
- npm
- Related libraries
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.