npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sap/xb-msg-amqp-v091

v0.9.12

Published

XB Messaging AMQP V091

Downloads

2,216

Readme

AMQP 0.9.1 Client Library

Provides a client implementation for AMQP v0.9.1

Table of contents

Prerequisites

Make sure to have a message broker available, e.g. RabbitMQ.

Install

See also: https://www.npmjs.com/package/@sap/xb-msg-amqp-v091

To add it to your project run:

npm i @sap/xb-msg-amqp-v091

To generate complete API documentation run inside the library package folder

npm run doc

Overview

This library provides a messaging client for AMQP v0.9.1. A single client instance represents one connection to the broker. Either TLS or NET socket is used depending on defined client options.

The API works completely asynchronous based on callbacks, often providing also done (resolve) and failed (reject) callbacks. This means it would be simple to use Promise objects in the application even if the client library so far does not use it.

AMQP v0.9.1 defines classes and methods (like remote procedure calls). Unfortunately, some of them do not allow a key-based mapping of responses to requests. Hence, for those methods the client has to wait for the response before a second request can be sent. The client encapsulates this and behaves always asynchronous for the caller.

Getting started

There are examples:

It shall run with defaults immediately if a RabbitMQ is installed at localhost:5672 with user guest/guest.

All examples accept individual settings, e.g. to use a remote host or to try different settings. It can be provided with a js-file given as command line parameter. The file shall just export the options. Run it like this if the file is stored in folder config, same level as examples.

node .\examples\producer.js ..\config\my-options.js

Feel free to start testing with the following file content:

'use strict';

module.exports = {
    net: {
        host          : '127.0.0.1',
        port          : 5672
    },
    sasl: {
        mechanism     : 'PLAIN',
        user          : 'guest',
        password      : 'guest'
    },
    amqp: {
        vhost         : '/'
    }
    data: {
        exchange      : 'amq.topic',
        routingKey    : 'a.b.c',
        confirms      : true,  // producer
        noAck         : false, // consumer
        prefetchCount : 1000,  // consumer
        payload       : Buffer.allocUnsafe(50).fill('X'),
        maxCount      : 10000,
        logCount      : 1000
    }
};

The data section is ignored by the client, it is just used by the example programs.

API

Create a client instance:

const options = {
    tls: {
        host: 'localhost',
        port: 5671,
        ca: [
            fs.readFileSync('../truststore/cacert.pem'),
            fs.readFileSync('../truststore/cert.pem')
        ]
    },
    net: {
        host: 'localhost',
        port: 5672,
    },
    sasl: {
        user: 'guest',
        password: 'guest'
    },
    amqp: {
        vhost: '/',
    }
};
const client = new AMQP.Client(options);

Either 'tls' attributes or 'net' attributes must be provided, 'tls' will be preferred.

It is also possible to provide connection data as URI:

const options = {
    uri: 'amqp://guest:guest@localhost:5672/vhost1?heartbeat=300' 
};
const client = new AMQP.Client(options);

Or using 'tls' again:

const options = {
    uri: 'amqps://guest:guest@localhost:5671?cacertfile=cacert.pem&cacertfile=cert.pem'
};
const client = new AMQP.Client(options);

Finally, also an array of URIs can be provided:

const options = {
    uri: [
        'amqp://guest:guest@localhost:5672/vh111',
        'amqp://guest:guest@localhost:5672/vh222'
    ]
};
const client = new AMQP.Client(options);

The client will start using the first URI and will try further URIs automatically in the given sequence until the connection can be established. If the client fails with all URIs then it stops and waits for another explicit call to connect. At this point an event 'disconnected' is raised.

An application that requires a permanent opened connection shall always handle the 'disconnect' event by calling client.connect() again, of course after a given delay time. Timers or other mechanisms may be used, depending on the application design. Keep in mind that NodeJS runtime does not guarantee precise timer execution, it depends on the event queue load.

Finally, URIs can also be combined with all other options settings. It will just overwrite those fields that are explicitly defined in the URI. A typical example could be the following:

const options = {
    uri: [
        'amqp://guest:guest@localhost:5672/vh111',
        'amqp://guest:guest@localhost:5672/vh222'
    ]
    istreams:
    {
        in1: {channel: 1, exchange: 'amq.topic', routingKey: 'a.b.c', noAck: true},
        in2: {channel: 1, exchange: '', routingKey: 'myQueue', noAck : false, prefetchCount : 1000}
    }
    ostreams:
    {
        out1: {channel: 1, exchange: 'amq.topic', routingKey: 'a.b.c', confirms : true},
        out2: {channel: 1, exchange: 'amq.topic', routingKey: 'x.y.z', confirms : false}
    }
};
const client = new AMQP.Client(options);