libamqp
v1.0.7
Published
This is the library to use amqp within the ACP platform.
Readme
AMQP Library for App Cloud Platform
This is the library to use amqp within the ACP platform.
Installation
Initialize the RabbitMq connection.
// config has rabbitMqConnection property
var RabbitMqConnection = require('lib-acp-amqp');
const rabbitMq = new RabbitMqConnection(config);Usage
// Configuration file
const fs = require('fs');
function AppSettings() {
const PUB_KEY = fs.readFileSync(__dirname + '/public-key.pem', 'utf8');
this.secretKey = PUB_KEY;
this.mongoTenants = '***';
this.redisHost = "***";
this.redisPass = "***",
this.rabbitMqConnection = "***";
this.mongoDb = (dbName) => {
return `mongodb://host:port/${dbName}`;
}
};
module.exports = AppSettings;class TestCommand {
constructor(msg) {
this.message = msg;
}
}Receive messages
// testMessageHandler.js
callback = (msg) => {
console.log("message received!!");
console.log(msg);
}
module.exports = callback ;// main.js
var testCallback = require('./handlers/TestMessageHandler');
rabbitMq.registerCallback(testCallback, TestCommand);
var handler = require('./handlers/TestMessageHandler');
rabbitMq.listen("TestExchange", "TestQueue", ch => {
ch.prefetch(1);
});Send messages
var command = new TestCommand("value");
rabbitMq.prepareChannel(ch => {
rabbitMq.sendToQueue("TestQueue", ch, command);
});