Skip to content

Commit

Permalink
Log rabbitmq channel allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Nov 2, 2024
1 parent 40b356e commit b276981
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gateway/listener/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { WebSocket } from "@spacebar/gateway";
import "missing-native-js-functions";
import { Channel as AMQChannel } from "amqplib";
import { Recipient } from "@spacebar/util";
import * as console from "node:console";

// TODO: close connection on Invalidated Token
// TODO: check intent
Expand Down Expand Up @@ -88,9 +89,12 @@ export async function setupListener(this: WebSocket) {
this.listen_options = opts;
const consumer = consume.bind(this);

console.log("[RabbitMQ] setupListener: open for ", this.user_id);
if (RabbitMQ.connection) {
console.log("[RabbitMQ] setupListener: opts.channel = ", typeof opts.channel, opts.channel);
opts.channel = await RabbitMQ.connection.createChannel();
opts.channel.queues = {};
console.log("[RabbitMQ] channel created: ", typeof opts.channel, opts.channel);
}

this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts);
Expand Down Expand Up @@ -128,6 +132,7 @@ export async function setupListener(this: WebSocket) {
});

this.once("close", () => {
console.log("[RabbitMQ] setupListener: close for ", this.user_id, "=", typeof opts.channel, opts.channel);
if (opts.channel) opts.channel.close();
else {
Object.values(this.events).forEach((x) => x?.());
Expand Down

0 comments on commit b276981

Please sign in to comment.