✨ RabbitMQ
This commit is contained in:
parent
2c9a661dd8
commit
675ef382ae
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@fosscord/server-util": "^1.3.49",
|
||||
"@fosscord/server-util": "^1.3.51",
|
||||
"@types/jest": "^26.0.22",
|
||||
"@types/json-schema": "^7.0.7",
|
||||
"ajv": "^8.4.0",
|
||||
@ -680,9 +680,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@fosscord/server-util": {
|
||||
"version": "1.3.49",
|
||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.49.tgz",
|
||||
"integrity": "sha512-raWZu89X17mnNta4lAX++i5KjE8o/o4YUuP0Rnj+uFTWvvt5QQKYvCcxc7SgkezS3f5vSEcelJ/xZlJjvES4Pg==",
|
||||
"version": "1.3.51",
|
||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.51.tgz",
|
||||
"integrity": "sha512-z7gAwj8UFTrbabtyMqb/7mhiTTpk07dKMu2ZaL4yeTPBR2Ppnkd3JqYHcrqIyMfeENgzTFoOVSjtun1aFUFDag==",
|
||||
"dependencies": {
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/mongoose-autopopulate": "^0.10.1",
|
||||
@ -11573,9 +11573,9 @@
|
||||
}
|
||||
},
|
||||
"@fosscord/server-util": {
|
||||
"version": "1.3.49",
|
||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.49.tgz",
|
||||
"integrity": "sha512-raWZu89X17mnNta4lAX++i5KjE8o/o4YUuP0Rnj+uFTWvvt5QQKYvCcxc7SgkezS3f5vSEcelJ/xZlJjvES4Pg==",
|
||||
"version": "1.3.51",
|
||||
"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.51.tgz",
|
||||
"integrity": "sha512-z7gAwj8UFTrbabtyMqb/7mhiTTpk07dKMu2ZaL4yeTPBR2Ppnkd3JqYHcrqIyMfeENgzTFoOVSjtun1aFUFDag==",
|
||||
"requires": {
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/mongoose-autopopulate": "^0.10.1",
|
||||
|
@ -33,7 +33,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/fosscord/fosscord-api#readme",
|
||||
"dependencies": {
|
||||
"@fosscord/server-util": "^1.3.49",
|
||||
"@fosscord/server-util": "^1.3.51",
|
||||
"@types/jest": "^26.0.22",
|
||||
"@types/json-schema": "^7.0.7",
|
||||
"ajv": "^8.4.0",
|
||||
|
@ -3,7 +3,7 @@ import fs from "fs";
|
||||
import { Connection } from "mongoose";
|
||||
import { Server, ServerOptions } from "lambert-server";
|
||||
import { Authentication, CORS } from "./middlewares/";
|
||||
import { Config, db } from "@fosscord/server-util";
|
||||
import { Config, db, RabbitMQ } from "@fosscord/server-util";
|
||||
import i18next from "i18next";
|
||||
import i18nextMiddleware, { I18next } from "i18next-http-middleware";
|
||||
import i18nextBackend from "i18next-node-fs-backend";
|
||||
@ -58,6 +58,7 @@ export class FosscordServer extends Server {
|
||||
await this.setupSchema();
|
||||
console.log("[Database] connected");
|
||||
await Config.init();
|
||||
await RabbitMQ.init();
|
||||
|
||||
this.app.use(CORS);
|
||||
this.app.use(Authentication);
|
||||
|
@ -113,8 +113,6 @@ router.post("/", messageUpload.single("file"), async (req: Request, res: Respons
|
||||
var body = req.body as MessageCreateSchema;
|
||||
const attachments: Attachment[] = [];
|
||||
|
||||
console.log(body);
|
||||
|
||||
if (req.file) {
|
||||
try {
|
||||
const file = await uploadFile(`/attachments/${channel_id}`, req.file);
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { Config, Event, EventModel, rabbitCon, rabbitCh } from "@fosscord/server-util";
|
||||
import { Config, Event, EventModel, RabbitMQ } from "@fosscord/server-util";
|
||||
|
||||
export async function emitEvent(payload: Omit<Event, "created_at">) {
|
||||
if (rabbitCon) {
|
||||
if (RabbitMQ.connection) {
|
||||
const id = (payload.channel_id || payload.user_id || payload.guild_id) as string;
|
||||
if (!id) console.error("event doesn't contain any id", payload);
|
||||
const data = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.data; // use rabbitmq for event transmission
|
||||
await RabbitMQ.channel?.assertQueue(id);
|
||||
|
||||
// assertQueue isn't needed, because a queue will automatically created if it doesn't exist
|
||||
const successful = rabbitCh.sendToQueue(id, Buffer.from(`${data}`), { type: payload.event });
|
||||
const successful = RabbitMQ.channel?.sendToQueue(id, Buffer.from(`${data}`), { type: payload.event });
|
||||
if (!successful) throw new Error("failed to send event");
|
||||
} else {
|
||||
// use mongodb for event transmission
|
||||
|
Loading…
x
Reference in New Issue
Block a user