Переглянути джерело

receiving message from queue

master
mikeyangelo5 2 роки тому
джерело
коміт
832bd26fa3
2 змінених файлів з 20 додано та 18 видалено
  1. +19
    -17
      index.mjs
  2. +1
    -1
      package.json

index.js → index.mjs Переглянути файл

@@ -8,7 +8,7 @@ import dotenv from 'dotenv'
dotenv.config()

const app = express()
const queue = process.env.queueName
const queueName = process.env.queueName
const senderEmail = "michael.pandu@ti.ukdw.ac.id"
// const mailTransporter = nodemailer.createTransport({
// service: 'gmail',
@@ -30,21 +30,21 @@ app.get('/', (_req, res) => {
res.status.send(200).send("Amigo Receipt Sender Service Homepage!")
})

// amqp.connect('amqp://192.168.100.14' ).then(async conn=> {
// const ch = await conn.createChannel()
// const queue = ch.assertQueue(queueName, { durable: true })
// if (queue) {
// queue.then(() => {
// return ch.consume(queueName, async (msg) => {
// var messageBody = msg.content.toJSON()
// console.log(`[*] Message Received! email : ${message.email} and pesan : `)
// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda")
// }, { noAck: true })
// }).then(() => {
// console.log('* Waiting for messages from queue ' + queueName)
// })
// }
// }).catch(console.warn)
amqp.connect('amqp://localhost' ).then(async conn=> {
const ch = await conn.createChannel()
const queue = ch.assertQueue(queueName, { durable: true })
if (queue) {
queue.then(() => {
return ch.consume(queueName, async (msg) => {
var messageBody = JSON.parse(msg.content.toString())
console.log(`[*] Message Received! email : ${messageBody.email} and pesan : ${messageBody.html}`)
// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda")
}, { noAck: true })
}).then(() => {
console.log('* Waiting for messages from queue ' + queueName)
})
}
}).catch(console.warn)

function sendReceipt(recepientEmail, receipt) {
var date = new Date()
@@ -61,6 +61,8 @@ function sendReceipt(recepientEmail, receipt) {
}, function(error) {
console.error(error)
})

// ============ GMAIL's ============
// var nodemailerOptions = {
// from: process.env.senderMail,
// to: receiverEmail,
@@ -77,4 +79,4 @@ function sendReceipt(recepientEmail, receipt) {
// })
}

sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda")
// sendReceipt("michael.pandu270@gmail.com", "Berikut detail nota terbaru anda")

+ 1
- 1
package.json Переглянути файл

@@ -1,6 +1,6 @@
{
"name": "emailnotification",
"version": "1.0.0",
"version": "2.0.0",
"description": "",
"main": "index.mjs",
"type": "module",


Завантаження…
Відмінити
Зберегти