checkpoint
This commit is contained in:
parent
626be7dae6
commit
89d2610cd9
1 changed files with 23 additions and 3 deletions
|
|
@ -11,11 +11,12 @@ import { Profile } from "../entities/Profile";
|
|||
|
||||
export let sendToQueue: (payload: any) => void;
|
||||
export let sendToQueueOrg: (payload: any) => void;
|
||||
export let sendToQueueOrgReport: (payload: any) => void;
|
||||
export async function init() {
|
||||
//----> (1) Producer
|
||||
if (!process.env.AMQ_URL || !process.env.AMQ_QUEUE || !process.env.AMQ_QUEUE_ORG) return;
|
||||
if (!process.env.AMQ_URL || !process.env.AMQ_QUEUE || !process.env.AMQ_QUEUE_ORG || !process.env.AMQ_QUEUE_REPORT) return;
|
||||
|
||||
const { AMQ_URL: url, AMQ_QUEUE: queue, AMQ_QUEUE_ORG: queue_org } = process.env; //----> (1.2) get url and queue from .env
|
||||
const { AMQ_URL: url, AMQ_QUEUE: queue, AMQ_QUEUE_ORG: queue_org, AMQ_QUEUE_REPORT: queue_org_report } = process.env; //----> (1.2) get url and queue from .env
|
||||
|
||||
const connection = await amqp.connect(url); //----> (1.3) set up url with amqp protocol
|
||||
|
||||
|
|
@ -40,9 +41,14 @@ export async function init() {
|
|||
channel.sendToQueue(queue_org, Buffer.from(JSON.stringify(payload)), { persistent });
|
||||
};
|
||||
|
||||
sendToQueueOrgReport = (payload: any, persistent = true) => {
|
||||
channel.sendToQueue(queue_org_report, Buffer.from(JSON.stringify(payload)), { persistent });
|
||||
};
|
||||
|
||||
console.log("[AMQ] Listening for message...");
|
||||
createConsumer(queue, channel, handler), //----> (3) Process Consumer
|
||||
createConsumer(queue_org, channel, handler_org);
|
||||
createConsumer(queue_org, channel, handler_org);
|
||||
createConsumer(queue_org_report, channel, handler_org_report);
|
||||
// createConsumer(queue2, channel, handler2);
|
||||
}
|
||||
|
||||
|
|
@ -172,3 +178,17 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handler_org_report(msg: amqp.ConsumeMessage): Promise<boolean> {
|
||||
//----> condition before process consume
|
||||
const { data, token, user } = JSON.parse(msg.content.toString());
|
||||
const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data;
|
||||
try {
|
||||
|
||||
console.log("[AMQ] Excecute Organization Success");
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue