-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email and email receive bode successfully
- Loading branch information
Showing
2 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |