Android project added

- Android can now send messages over RabbitMQ to the backend.
This commit is contained in:
2020-10-19 22:19:28 +02:00
parent 48140f557b
commit f722ee9595
56 changed files with 1522 additions and 12 deletions

21
backend/lib/rabbit.ts Normal file
View 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));
}
}