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-connection-manager-rpcx

v1.3.7

Published

Extend amqp-connection-manager to support RPC.

Downloads

10

Readme

NPM Package Build Status Coverage Status Greenkeeper badge semantic-release

Dependency Status devDependency Status peerDependency Status

Extend amqp-connection-manager connection management for amqplib to support Remote procedure call (RPC).

amqp-connection-manager-rpc

Features

  • Time to live for RPC requests.
  • Exceptions transmitted from RPC server to RPC client.
  • Simple async function API design

Installation

npm install --save amqplib amqp-connection-manager amqp-connection-manager-rpc

Basics

The basic idea described at rabbitmq. To manage responses from an RPC server, node-cache is used.

Here's the RPC client example:

var amqp = require('amqp-connection-manager-rpc');

// Create a new connection manager
var connection = amqp.connect(['amqp://localhost'], {json: true});

// Setup a channel for RPC requests.
const ttl = 60; // Time to live for RPC request (seconds). 0 - infinite
var channelWrapper = connection.createRPCClient('RPC-QUEUE-test', ttl);

// Send some request to RPC server and receive reply. Exception can occupied!
let req = { a: 1, b: 2}; //request data
try{
    let prc_reply = await channelWrapper.sendRPC(req);
    console.log("RPC reply: ", prc_reply);
} catch (err) {
    console.log("RPC error: ", err);
}

Here's the RPC server example:

var amqp = require('amqp-connection-manager-rpc');

// Create a new connection manager
var connection = amqp.connect(['amqp://localhost'], {json: true});

// Set up a channel for RPC requests.
var channelWrapper = connection.createRPCServer('RPC-QUEUE-test', doRpcJob);

//do RPC job
async function doRpcJob(msgJson, msg) {
    if (!msgJson.b) throw new Error('B is not set'); //Exceptions allowed! Will be send to RPC client.
    let reply = {
        a: msgJson.a ? msgJson.a + 1 : null
    }
    return reply;
}

See a complete example in the examples folder.

API

See amqp-connection-manager API.

AmqpConnectionManager#createRPCClient(queue_name[, ttl [, setup]])

Create a new RPC client ChannelWrapper.

  • queue_name - Name of queue for RPC request.
  • ttl - time to live for RPC request (seconds). To infinite set to 0. If not defined used 0.
  • setup - async function(channel) for setup queue and exchange. Must return RPC queue. Default: async function (channel) => { return await channel.assertQueue('', { exclusive: true }) };

Returns ChannelWrapper

AmqpConnectionManager#createRPCServer(queue_name, callback[, options] )

Create a new RPC server ChannelWrapper.

  • queue_name - Name of queue for RPC request.
  • callback - A callback function, which returns a Promise. This should return RPC server json reply. Callback function has two argument: json message from RPC client, full message from RPC client.

Options:

  • options.sendErrorStack - if true errors stack will be send to client. Default - false.
  • options.setup - async function(channel) for setup channel, exchange. Must return RPC queue name. Default: async function (channel) => { channel.prefetch(1); await channel.assertQueue(queue_name, { durable: false }); return queue_name; };

Returns ChannelWrapper

ChannelWrapper#sendRPC(msg [,ttl [, exchangeName [, routingKey]]])

Send RPC request to RPC server. Call it on client only.

  • msg - request Object to RPC server.
  • ttl - time to live for RPC request (seconds). To infinite set to 0. If not defined used value from createRPCClient().
  • exchangeName - name of exchange for RPC request.
  • routingKey - routing key for RPC request.

Returns Object with RPC job reply or Exception

Fork it!

Pull requests, issues, and feedback are welcome.