Files
Livebeat/backend/lib/rabbit.ts
Mondei1 f722ee9595 Android project added
- Android can now send messages over RabbitMQ to the backend.
2020-10-19 22:19:28 +02:00

21 lines
688 B
TypeScript

import * as amqp from 'amqplib';
import { logger, RABBITMQ_URI } from '../app';
export class RabbitMQ {
connection: amqp.Connection | null = null;
channel: amqp.Channel | null = null;
async init() {
this.connection = await amqp.connect(RABBITMQ_URI);
this.channel = await this.connection.createChannel();
this.channel.consume('Tracker', (msg) => {
logger.debug("Received from broker: " + msg?.content.toString());
}, { noAck: false });
}
async publish(queueName = 'Tracker', data: any) {
if (this.connection == undefined) await this.init()
this.channel?.sendToQueue(queueName, Buffer.from(data));
}
}