rabbitmq

This commit is contained in:
Flam3rboy 2021-08-11 19:29:39 +02:00
parent 08dee5c847
commit d8eece32de
5 changed files with 41 additions and 18 deletions

BIN
package-lock.json generated

Binary file not shown.

View File

@ -32,6 +32,7 @@
"@types/mongoose-lean-virtuals": "^0.5.1", "@types/mongoose-lean-virtuals": "^0.5.1",
"@types/node": "^14.14.25", "@types/node": "^14.14.25",
"ajv": "^8.5.0", "ajv": "^8.5.0",
"amqplib": "^0.8.0",
"dot-prop": "^6.0.1", "dot-prop": "^6.0.1",
"env-paths": "^2.2.1", "env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
@ -40,5 +41,8 @@
"mongoose": "^5.12.3", "mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3", "mongoose-autopopulate": "^0.12.3",
"typescript": "^4.1.3" "typescript": "^4.1.3"
},
"devDependencies": {
"@types/amqplib": "^0.8.1"
} }
} }

View File

@ -25,17 +25,17 @@ export interface RateLimitOptions {
} }
export interface Region { export interface Region {
id: string, id: string;
name: string, name: string;
vip: boolean, vip: boolean;
custom: boolean, custom: boolean;
deprecated: boolean, deprecated: boolean;
optimal: boolean, optimal: boolean;
} }
export interface KafkaBroker { export interface KafkaBroker {
ip: string, ip: string;
port: number port: number;
} }
export interface DefaultOptions { export interface DefaultOptions {
@ -133,10 +133,13 @@ export interface DefaultOptions {
regions: { regions: {
default: string; default: string;
available: Region[]; available: Region[];
} };
rabbitmq: {
host: string | null;
};
kafka: { kafka: {
brokers: KafkaBroker[] | null brokers: KafkaBroker[] | null;
} };
} }
export const DefaultOptions: DefaultOptions = { export const DefaultOptions: DefaultOptions = {
@ -230,17 +233,18 @@ export const DefaultOptions: DefaultOptions = {
}, },
regions: { regions: {
default: "fosscord", default: "fosscord",
available: [ available: [{ id: "fosscord", name: "Fosscord", vip: false, custom: false, deprecated: false, optimal: false }],
{ id: "fosscord", name: "Fosscord", vip: false, custom: false, deprecated: false, optimal: false }, },
] rabbitmq: {
host: null,
}, },
kafka: { kafka: {
brokers: null brokers: null,
} },
}; };
export const ConfigSchema = new Schema({}, { strict: false }); export const ConfigSchema = new Schema({}, { strict: false });
export interface DefaultOptionsDocument extends DefaultOptions, Document { } export interface DefaultOptionsDocument extends DefaultOptions, Document {}
export const ConfigModel = model<DefaultOptionsDocument>("Config", ConfigSchema, "config"); export const ConfigModel = model<DefaultOptionsDocument>("Config", ConfigSchema, "config");

14
src/util/RabbitMQ.ts Normal file
View File

@ -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 };

View File

@ -5,4 +5,5 @@ export * from "./MessageFlags";
export * from "./Permissions"; export * from "./Permissions";
export * from "./Snowflake"; export * from "./Snowflake";
export * from "./UserFlags"; export * from "./UserFlags";
export * from "./toBigInt" export * from "./toBigInt";
export * from "./RabbitMQ";