summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/RabbitMQ.ts26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/util/RabbitMQ.ts b/src/util/RabbitMQ.ts
index 9df95231..9da41990 100644
--- a/src/util/RabbitMQ.ts
+++ b/src/util/RabbitMQ.ts
@@ -1,14 +1,18 @@
 import amqp, { Connection, Channel } from "amqplib";
 import Config from "./Config";
 
-var rabbitCon: Connection;
-var rabbitCh: Channel;
-
-export async function init() {
-	const host = Config.get().rabbitmq.host;
-	if (!host) return;
-	rabbitCon = await amqp.connect(host);
-	rabbitCh = await rabbitCon.createChannel();
-}
-
-export { rabbitCon, rabbitCh };
+export const RabbitMQ: { connection: Connection | null; channel: Channel | null; init: () => Promise<void> } = {
+	connection: null,
+	channel: null,
+	init: async function () {
+		const host = Config.get().rabbitmq.host;
+		if (!host) return;
+		console.log(`[RabbitMQ] connect: ${host}`);
+		this.connection = await amqp.connect(host, {
+			timeout: 1000 * 60,
+		});
+		console.log(`[RabbitMQ] connected`);
+		this.channel = await this.connection.createChannel();
+		console.log(`[RabbitMQ] channel created`);
+	},
+};