Skip to content

Commit

Permalink
feat: add cluster header + connection name (#469)
Browse files Browse the repository at this point in the history
Added a connection name to easily see what cluster is connected to RabbitMQ
  • Loading branch information
Nidrux authored Mar 17, 2024
1 parent 148579f commit 7ef452c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "would-you",
"version": "1.3.9",
"version": "1.3.10",
"description": "Would you rather die or use this bot. You got the choice",
"main": "dist/cluster.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface IQueueMessage {
};
channelId: string | null;
retries: number;
location: {
shard: number;
cluster: number;
};
}
export type Result<T, E extends Error = Error> =
| { success: true; result: T }
Expand Down
6 changes: 3 additions & 3 deletions src/util/dailyMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class DailyMessage {
async listen() {
console.log(this.client.cluster.count);
const URL = process.env.RABBITMQ_URL || "fallback";
const connection = await amqplib.connect(URL);
const connection = await amqplib.connect(URL, { clientProperties: { connection_name: `client-cluster-${this.client.cluster.id}` } });
let QUEUE = `cluster-${this.client.cluster.id}`;
if (connection) {
const channel = await connection.createChannel();
Expand All @@ -25,7 +25,6 @@ export default class DailyMessage {
await channel.assertQueue(QUEUE, {
durable: false,
deadLetterExchange: "DLX",

deadLetterRoutingKey: "nVZzaJrwJ9",
});
channel.consume(QUEUE, async (message) => {
Expand Down Expand Up @@ -74,6 +73,7 @@ export default class DailyMessage {
message: IQueueMessage,
properties: MessageProperties,
): Promise<Result<string>> {
console.log(message)
if (message.channelId == null) {
return {
success: false,
Expand Down Expand Up @@ -210,7 +210,7 @@ export default class DailyMessage {
reason: string,
message: amqplib.Message,
) {
const headers = { rejectionCause: reason };
const headers = { rejectionCause: reason, cluster: this.client.cluster.id};
channel.publish("DLX", "key", message.content, {
headers: headers,
messageId: message.properties.messageId,
Expand Down

0 comments on commit 7ef452c

Please sign in to comment.