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-factory

v1.1.4

Published

Node.js AMQP RPC Consumer and Publisher Factory

Downloads

82

Readme

amqp-rpc-factory

Node.js AMQP RPC Consumer and Publisher Factory

The consumer and publisher make pervasive use of Javascript Promises.

Build Status Coverage Status NPM version Dependency Status

Code review, suggestions and pull requests very much welcome - thanks!

Credits

Dependencies

Overview

RabbitMQ is a message broker.

Messaging brokers receive messages from publishers (applications that publish them, also known as producers) and route them to consumers (applications that process them).

amqp-rpc-factory creates AMQP RPC consumers and publishers.

Here's an image from the RabbitMQ website giving an overview of the RPC messaging process.

In this context Node.js is the blue circles, in between Node.js is TCP networking and the RabbitMQ server.

RPC Overview

For more details see the RabbitMQ Tutorial - Remote procedure call (RPC)

Features

  • Create an RPC consumer
  • Create an RPC producer (command line use opens and closes a TCP connection per message)
  • Create an RPC producer (server use opens a single TCP connection then opens and closes channels per message)
  • Consumer graceful error control and retry
  • Producer graceful error control and timeout

Install

  • npm install amqp-rpc-factory

Usage Example

  • Create a simple RPC consumer and publisher that connect to a RabbitMQ server running on localhost
  • The publisher will send a text string, the consumer will append '-OK' to the text string and return it.
  • You will need two terminals, one for the consumer and one for the producer

Consumer - rpc-consumer.js

// Usage: node rpc-consumer.js

var consumerOptions = {
  url: process.env.RABBITMQ_URL || 'localhost'
};

var consumer = require('amqp-rpc-factory').consumer.create(consumerOptions);

consumer.run();

Publisher - rpc-publisher.js

// Usage: node rpc-publisher.js

var rpcPublisherFactory = require('amqp-rpc-factory').publisher;

var publisher = rpcPublisherFactory.create({
  standalone: true,
  url: process.env.RABBITMQ_URL || 'localhost'
});

publisher.publish('message in a bottle')
  .then(function publishSuccess(res) {
    console.log(res);
  })
  .catch(function publishError(err) {
    console.log(err);
  });

Check out the examples for more details of the basic, advanced, advanced-jsonrpc and server features.

Consumer Options

  • processMessage: The function to handle processing the RPC request. Can standard Javascript Function or return a fulfilled Promise.
  • connectionRetryInterval: default: 500ms
  • url: default: 'localhost' - A valid amqp URI.
  • socketOptions: default empty Object - The socket options will be passed to the socket library (net or tls). The socket options may also include the key noDelay, with a boolean value. If the value is true, this sets TCP_NODELAY on the underlying socket.
  • queue: default: 'node_rpc_queue'
  • queueOptions : default: {durable: true} - AMQP options passed to the queue. You may find autoDelete: true useful in place of durable if you wish the request queues cleaned up automatically.
  • prefetch : default : 1 - Set the prefetch count for this channel. The count given is the maximum number of messages sent over the channel that can be awaiting acknowledgement. To consume multiple requests in the same process, in parallel, this must be set to greater than 1.
  • logInfo: Log non-error messages, default console.info - Can pass in custom logger (example Bunyan)
  • logError: Log error messages, default console.warn - Can pass in custom logger (example Bunyan)

Publisher Options

  • debugLevel: default: 0 - level 1 will log sent messages, level 2 will also log received messages
  • replyTimeOutInterval: default: 3000 milliseconds - publisher timeout waiting for replies
  • standalone: default: false - If true, close the connection on finish, otherwise just close the channel.
  • url: default: 'localhost' - A valid amqp URI.
  • socketOptions: default empty Object - The socket options will be passed to the socket library (net or tls). The socket options may also include the key noDelay, with a boolean value. If the value is true, this sets TCP_NODELAY on the underlying socket.
  • queue: default: 'node_rpc_queue'
  • queueOptions : default: {exclusive: true, autoDelete: true} - AMQP options passed to the queue.
  • logInfo: Log non-error messages, default console.log - Can pass in custom logger (example Bunyan)
  • logError: Log error messages, default console.log - Can pass in custom logger (example Bunyan)

Tests

  • git clone [email protected]:rudijs/amqp.node-rpc-factory.git
  • cd amqp.node-rpc-factory
  • npm install
  • gulp test
  • TEST_QUIET=true gulp test (stubs out the logging output on the console)
  • gulp lint

Development

  • gulp watch-test
  • TEST_QUIET=true watch-test
  • gulp watch-lint