Newer
Older
import * as amqp from 'amqplib/callback_api';
import { Email } from './email';
@Injectable()
export class EmailService {
send(email: Email) {
const rabbitmqUrl = 'amqp://user:password123@0.0.0.0:5672';
const mailerQueue = 'portail-data-send-email';
// Connect to rabbitmq
amqp.connect(rabbitmqUrl, (err, conn) => {
// Create a communication channel
conn.createChannel((error, ch) => {
// Stringify and bufferise message
const buffer = Buffer.from(JSON.stringify(email));
ch.assertQueue(mailerQueue, { durable: true });
ch.sendToQueue(mailerQueue, buffer);
Logger.log(`sent to queue ${mailerQueue}: ${JSON.stringify(email)}`);