Skip to content

Commit

Permalink
email and email receive bode successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
zobkazi committed May 21, 2024
1 parent 178a17b commit 8a2cc46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/services/email/src/EmailBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const emailBody = async (req: Request, res: Response, next: NextFunction) => {
try {
const { email } = req.body;

console.log(email);
res.status(200).json({
message: "Email body fetched successfully",
data: email,
});
} catch (error) {
next(error);
}
Expand Down
43 changes: 39 additions & 4 deletions packages/services/email/src/utils/receiver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import amqp from "amqplib";
import {defaultSender, transporter} from '@/config'
import { defaultSender, transporter } from "@/config";

const receiveFromQueue = async (
queue: string,
callback: (message: string) => void
) => {
try {
const connection = await amqp.connect("amqp://localhost");

const receiveFromQueue = async (queue: string, callback: (message: string) => void) => {

}
const channel = await connection.createChannel();

await channel.assertQueue(queue);

channel.consume(queue, (message) => {
if (message) {
callback(message.content.toString());
}

channel.ack(message);

connection.close();
});
} catch (error) {
console.log(error);
}
};

export const sendToQueue = async (queue: string, message: string) => {
try {
const connection = await amqp.connect("amqp://localhost");
const channel = await connection.createChannel();
await channel.assertQueue(queue);
await channel.sendToQueue(queue, Buffer.from(message));
await channel.close();
await connection.close();
} catch (error) {
console.log(error);
}
};

export default receiveFromQueue;

0 comments on commit 8a2cc46

Please sign in to comment.