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

node-msgr

v0.4.0

Published

A node AMQP client built to play nice with the msgr Rails gem.

Downloads

8

Readme

node-msgr

node-msgr is a node amqp client built on top of libamqp and meant to be a companion to the ruby msgr gem. It supports standard publishing and consuming as well as the RPC pattern. By convention all queues are bound to the msgr exchange and the client deals exclusively with routing keys on this exchange instead of individual queue names.

Connecting to a rabbit server

To begin using the client create a new instance with the url for the server you want to connect to as an argument to the constructor.

const msgr = new Msgr('amqp://myserverurl');

This will immediately return a usable client instance.

Publishing a message

Publishing a message to the exchange is done with the publish() method. The first argument is the routing key and the second is the data you want to send and can be anything serializable by JSON.stringify(). There is an optional third parameter to set options when publishing that is passed through to libamqp. Available options are documented here.

const data = {
    some: "thing",
    to: "send"
};
msgr.publish('my_topic', data);

Consuming messages

Consuming messages requires a routing key and a callback. Consuming can also take an optional third param to configure the consumer/queue. Those options are documented here.

msgr.consume('my_topic', (message) => {
    // do a thing with the message
});

A message will be an object with:

  • A content property containing the deserialized body of the message
  • properties and fields properties containing some additional informationa about the message mostly used internally by libamqp. See the libamqp docs for more info.
  • An ack method for use if the queue requires messages to be acknowledged. This method is available on every message, even if the originating queue was created with noAck: true. Calling this method on a message that cannot be acknowledged will cause an error.

RPC

The rpcExec() method takes the same set of parameters as publish() including options. It returns a promise that will be resolved with the content of the reply message (not the message itself) or be rejected with either a timeout error or an error provided by the rpc server. The default timeout is 15 seconds and can be adjusted by setting the timeout option with the desired value in milliseconds. The response from the rpc server is expected to be an object with three properties, data, trace, and error.

const data = {
    some: "thing",
    to: "send"
};
msgr.rpcExec('my_topic', data).then((response) => {
    // do a thing with the response
});

Client Errors

If the value of error is true and trace is falsy then data is presumed to be an array of error messages for the client. The promise will be rejected with an InputError containing a generic message and the value of data will be appended to the error object as clientMessages.

{
    message: 'Client error',
    clientMessages: ['Error messages from the consumer'],
    ...
}

Consumer Errors

If the consumer encounters and unhandled error processing the message the trace property will be set to a truthy value, usually the stack trace from the consumer's error. In this case the promise will be rejected with a generic error and no additional feedback is provided.

{
    message: 'Fatal consumer error',
    ...
}

Caveats

  • Only JSON payloads are supported
  • There is no method for creating an RPC server/listener (yet)