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

amqp-rpc-client

v2.0.1

Published

Production ready, simple, promise-based and callback compatible AMQP RPC client.

Downloads

5

Readme

What is amqp-rpc-client?

It is a production ready, simple, promise-based and callback compatible AMQP RPC client.

Quick start

npm install amqp-rpc-client

Then:

var AmqpRpcClient = require('amqp-rpc-client');
var rpcClient = new AmqpRpcClient('myhost');
var publishResult = rpcClient.publish('myQueue', {message: 'awesome!'});

Reference

This is a reference for version 2.x. If you are looking for version 1.x, go here.

RpcClient

The client must be initialized prior to usage. You may have any number of client instances running, but you probably need only one instance.

The initialization with a command like var rpcClient = new AmqpRpcClient();. You may provide a host to connect to as the only parameter of the client.

The client instance exposes the following methods:

  • setExchange
  • setPublishMessageTransformer
  • setResponseMessageHandler
  • publish

Both publish message transformer and response handler have default functions set.

The publish method stringifies message and converts to Buffer, if not already Buffer.

RpcClient.defaultPublishMessageTransformer = function(message) {
    if (message instanceof Buffer) {
        return message;
    } else {
        var stringifiedMessage = JSON.stringify(message);
        return new Buffer(stringifiedMessage);
    }
};

The response handler converts Buffer to JSON and reads information in state property.

RpcClient.defaultResponseMessageHandler = function(fulfill, reject, progress) {
    return function jsonMessageHandlerParser(message) {
        if (!message) {
            return reject('Consumer was canceled');
        }
    
        var content = JSON.parse(message.content.toString());

        if (progress && content.state === 'running') {
            progress(content);
        }
        else if (content.state === 'finished') {
            fulfill(content);
        }
        else if (content.state === 'rejected') {
            reject(content);
        }
    };
};

publish(queue:String, message:*, [[options:Object], [callback:Function]])

Publishes message on given queue. You may provide an options object with the following properties:

  • exchange:String Overrides client exchange. Defaults to ''.
  • progressCallback:Function Optional callback to be called when the received message is not final. It is only useful if the server sends such kind of messages and if response message parser cares about them.

Optional callback may be provided. Method returns a promise that is fulfilled or rejected according to the function specified with setResponseMessageHandler or with default function.

setExchange(String)

Sets the exchange for all client calls. May be set individually as an option in publish.

setPublishMessageTransformer(Function)

The provided transformer receives the message given on the publish method and should return a Buffer that will be sent to queue on the same method.

setResponseMessageHandler(Function)

The provided response handler receives 3 parameters: fulfill, rejection and running callbacks.

The handler must return a function which receives a single parameter: A message of type Buffer.

For obvious reasons, either fulfill or reject callback must be called.