From d8eece32de3b509c9171d0769d042fab672439e1 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 11 Aug 2021 19:29:39 +0200 Subject: :sparkles: rabbitmq --- src/util/Config.ts | 38 +++++++++++++++++++++----------------- src/util/RabbitMQ.ts | 14 ++++++++++++++ src/util/index.ts | 3 ++- 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 src/util/RabbitMQ.ts (limited to 'src') diff --git a/src/util/Config.ts b/src/util/Config.ts index cbdc194c..10dddc88 100644 --- a/src/util/Config.ts +++ b/src/util/Config.ts @@ -25,17 +25,17 @@ export interface RateLimitOptions { } export interface Region { - id: string, - name: string, - vip: boolean, - custom: boolean, - deprecated: boolean, - optimal: boolean, + id: string; + name: string; + vip: boolean; + custom: boolean; + deprecated: boolean; + optimal: boolean; } export interface KafkaBroker { - ip: string, - port: number + ip: string; + port: number; } export interface DefaultOptions { @@ -133,10 +133,13 @@ export interface DefaultOptions { regions: { default: string; available: Region[]; - } + }; + rabbitmq: { + host: string | null; + }; kafka: { - brokers: KafkaBroker[] | null - } + brokers: KafkaBroker[] | null; + }; } export const DefaultOptions: DefaultOptions = { @@ -230,17 +233,18 @@ export const DefaultOptions: DefaultOptions = { }, regions: { default: "fosscord", - available: [ - { id: "fosscord", name: "Fosscord", vip: false, custom: false, deprecated: false, optimal: false }, - ] + available: [{ id: "fosscord", name: "Fosscord", vip: false, custom: false, deprecated: false, optimal: false }], + }, + rabbitmq: { + host: null, }, kafka: { - brokers: null - } + brokers: null, + }, }; export const ConfigSchema = new Schema({}, { strict: false }); -export interface DefaultOptionsDocument extends DefaultOptions, Document { } +export interface DefaultOptionsDocument extends DefaultOptions, Document {} export const ConfigModel = model("Config", ConfigSchema, "config"); diff --git a/src/util/RabbitMQ.ts b/src/util/RabbitMQ.ts new file mode 100644 index 00000000..9df95231 --- /dev/null +++ b/src/util/RabbitMQ.ts @@ -0,0 +1,14 @@ +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 }; diff --git a/src/util/index.ts b/src/util/index.ts index 7e8bca20..7523a6ad 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -5,4 +5,5 @@ export * from "./MessageFlags"; export * from "./Permissions"; export * from "./Snowflake"; export * from "./UserFlags"; -export * from "./toBigInt" \ No newline at end of file +export * from "./toBigInt"; +export * from "./RabbitMQ"; -- cgit 1.4.1