-
Notifications
You must be signed in to change notification settings - Fork 37
Home
Amqp-ts is a library for nodejs that simplifies communication with AMQP message busses written in Typescript. It has been tested on RabbitMQ. It uses the amqplib library by Michael Bridgen (squaremo).
This is a work in progress, currently in a late beta state.
It is compatible with the Typescript 1.6 module type definition resulution for node.js.
It does depend on the following npm libraries:
The DefinitelyTyped [tsd] tool is used to manage the typescript type definitions.
No need to nest functionality, just create a connection, declare your exchanges, queues and bindings and send and receive messages. The library takes care of any direct dependencies.
If you define an exchange and a queue and bind the queue to the exchange and want to make
sure that the queue is connected to the exchange before you send a message to the exchange you can call the connection.completeConfiguration()
method and act on the promise it returns.
import * as Amqp from "amqp-ts";
var connection = new Amqp.Connection("amqp://localhost");
var exchange = connection.declareExchange("ExchangeName");
var queue = connection.bind("QueueName");
queue.bind(exchange);
queue.startConsumer((message) => {
console.log("Message received: " + message);
}
// it is possible that the following message is not received because
// it can be sent before the queue, binding or consumer exist
exchange.send("Test");
connection.completeConfiguration().then(() => {
// the following message will be received because
// everything you defined earlier for this connection now exists
exchange.send("Test2");
});
var Amqp = require("amqp-ts");
var connection = new Amqp.Connection("amqp://localhost");
var exchange = connection.declareExchange("ExchangeName");
var queue = connection.bind("QueueName");
queue.bind(exchange);
queue.startConsumer(function (message) {
console.log("Message received: " + message);
}
// it is possible that the following message is not received because
// it can be sent before the queue, binding or consumer exist
exchange.send("Test");
connection.completeConfiguration().then(function () {
// the following message will be received because
// everything you defined earlier for this connection now exists
exchange.send("Test2");
});
When the library detects that the connection with the AMQP server is lost, it tries to automatically reconnect to the server.
This is still an experimental feature and has not been thoroughly tested.
TODO: describe winston configuration. Maybe changed or removed in future versions.