1.0.7 • Published 3 years ago

libamqp v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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);
});

License

MIT

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago