summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 16:45:23 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 16:45:23 +0200
commitca432f99b918a9ad0f3bb2c07c6fa98a3cb062e4 (patch)
tree2c4ee6b148ea138a17e53ba172643d56672ed251 /src/util
parentMerge branch 'master' of https://github.com/fosscord/fosscord-server-util (diff)
downloadserver-ca432f99b918a9ad0f3bb2c07c6fa98a3cb062e4.tar.xz
fix rabbitmq export
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`);
+	},
+};