Android project added
- Android can now send messages over RabbitMQ to the backend.
This commit is contained in:
21
backend/lib/rabbit.ts
Normal file
21
backend/lib/rabbit.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user