1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 10:22:39 +01:00

Log rabbitmq channel allocations

This commit is contained in:
Emma [it/its]@Rory& 2024-11-02 21:06:18 +01:00
parent 40b356ecdf
commit b2769812fa

View File

@ -34,6 +34,7 @@ import { WebSocket } from "@spacebar/gateway";
import "missing-native-js-functions"; import "missing-native-js-functions";
import { Channel as AMQChannel } from "amqplib"; import { Channel as AMQChannel } from "amqplib";
import { Recipient } from "@spacebar/util"; import { Recipient } from "@spacebar/util";
import * as console from "node:console";
// TODO: close connection on Invalidated Token // TODO: close connection on Invalidated Token
// TODO: check intent // TODO: check intent
@ -88,9 +89,12 @@ export async function setupListener(this: WebSocket) {
this.listen_options = opts; this.listen_options = opts;
const consumer = consume.bind(this); const consumer = consume.bind(this);
console.log("[RabbitMQ] setupListener: open for ", this.user_id);
if (RabbitMQ.connection) { if (RabbitMQ.connection) {
console.log("[RabbitMQ] setupListener: opts.channel = ", typeof opts.channel, opts.channel);
opts.channel = await RabbitMQ.connection.createChannel(); opts.channel = await RabbitMQ.connection.createChannel();
opts.channel.queues = {}; 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); this.events[this.user_id] = await listenEvent(this.user_id, consumer, opts);
@ -128,6 +132,7 @@ export async function setupListener(this: WebSocket) {
}); });
this.once("close", () => { this.once("close", () => {
console.log("[RabbitMQ] setupListener: close for ", this.user_id, "=", typeof opts.channel, opts.channel);
if (opts.channel) opts.channel.close(); if (opts.channel) opts.channel.close();
else { else {
Object.values(this.events).forEach((x) => x?.()); Object.values(this.events).forEach((x) => x?.());