Skip to content
abreits edited this page Nov 19, 2015 · 18 revisions

amqp-ts (AMQP TypeScript)

Table of Contents

  • Overview
  • [What's New](What's New)
  • Roadmap
  • [Building the Library](Building the Library)
  • [API Reference](API Reference)

Overview

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).

Defining Features
  • [High level non opinioned library], no need to worry about channels etc.
  • 'Lazy' initialization, async AMQP dependencies are resolved automatically
  • Automatic reconnection, when the connection with the AMQP server fails, the whole connection and configuration is rebuilt automatically
  • Written in typescript, it is compatible with the Typescript 1.6 module type definition resulution for node.js.
Current status

This is a work in progress, currently in a late beta state.

It does depend on the following npm libraries:

The DefinitelyTyped tsd tool is used to manage the typescript type definitions.

Lazy Initialization

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.

ES6/Typescript Example
import * as Amqp from "amqp-ts";

var connection = new Amqp.Connection("amqp://localhost");
var exchange = connection.declareExchange("ExchangeName");
var queue = connection.declareQueue("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.publish("Test");

connection.completeConfiguration().then(() => {
    // the following message will be received because
    // everything you defined earlier for this connection now exists
    exchange.publish("Test2");
});
Javascript Example
var Amqp = require("amqp-ts");

var connection = new Amqp.Connection("amqp://localhost");
var exchange = connection.declareExchange("ExchangeName");
var queue = connection.declareQueue("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.publish("Test");

connection.completeConfiguration().then(function () {
    // the following message will be received because
    // everything you defined earlier for this connection now exists
    exchange.publish("Test2");
});

Automatic Reconnection

When the library detects that the connection with the AMQP server is lost, it tries to automatically reconnect to the server.

Clone this wiki locally