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

amqprpc

v0.0.2

Published

RPC library built on top of amqplib

Downloads

2

Readme

amqprpc

RPC library built on top of amqplib

Features

  • Built on solid foundations
  • Client timeout support
  • Events for analytics or error handling

Usage

$ npm install amqprpc

RPC Server

Example

var amqp = require('amqplib');

amqp.connect('amqp://localhost/test').then(function(conn) {
  conn.createChannel().then(function(channel) {

  // magic happens here
  rpc.Server({ channel: channel, api: api });
}, console.error);

// any object with methods that return a promise
var api = {
  add: function(one, two) {
    this.resolve(one + two);
  },
  json: function(j) {
    this.resolve(j);
  },
  args: function(a, b, c) {
    this.resolve([a, b, c]);
  },
  reject: function(err) {
    this.reject(err || 'some error');
  },
  timeout: function() {
    setTimeout(this.resolve, 1000);
  }
};

Options

 * {String}   [queue.name=rpc]                   RPC queue name
 * {Object}   [queue.options={ durable:true }]   RPC queue options used to create the queue on the server

Events

connected

Emitted when the server successfully binds to the amqp queue

request

Emitted when a new request is received from a client

response

Emitted after the request has been processed and before the response is sent to the client

error

Errors thrown by the API functions are caught and passed to the client. These errors are thrown on the client side.

However, if any other error occurs, it is emitted as the error event. You can catch this error if needed, otherwise it will bubble up as an uncaughtException.

server.on('error', function(err) {
  log.critical(err);
  process.exit(1);
});

RPC Client

Example

var amqp = require('amqplib');

amqp.connect('amqp://localhost/test').then(function(conn) {
  conn.createChannel().then(function(channel) {

  var client = new rpc.Client({ channel: channel, timeout: 100 });

  // call api method
  client.call('add', [1, 2])
    .then(console.info)
    .catch(console.error);

  // optional
  rpc.Client.addMethods(client, ['add', 'json', 'args', 'reject', 'timeout']);
  client.add(1, 2)
    .then(console.info)
    .catch(console.error);
}, console.error);

var api = {
  add: function(one, two) {
    this.resolve(one + two);
  },
  json: function(j) {
    this.resolve(j);
  },
  args: function(a, b, c) {
    this.resolve(a, b, c);
  },
  reject: function(err) {
    this.reject(err || 'some error');
  },
  timeout: function() {
    setTimeout(this.resolve, 1000);
  }
};

Options

 * {Number}        [timeout=10000]                    Timeout in milliseconds, defaults to 10 seconds
 * {String}        [queue.name=rpc]                   RPC queue name
 * {Object}        [responseQueue.options={exclusive:true}] Options used for creating the response queue
 * {Object}        [responseQueue.consumeOptions={noAck:true}] Options used for consuming the response queue

Events

connected

Emitted when the client successfully binds to the amqp queue

request

Emitted when a new request is received

response

Emitted once a response is recived from the server

invalid id

Emitted if the request id does not match a pending promise

error

Errors thrown by the API functions are caught and passed to the application code.

However, if any other error occurs such as failing to bind to the amqp queue, it is emitted as the error event. You can catch this error if needed, otherwise it will bubble up as an uncaughtException.

client.on('error', function(err) {
  log.critical(err);
  process.exit(1);
});

Changelog

v0.0.2 (17 Feb 2015)

  • Minor docco updates

v0.0.1 (12 Feb 2015)

  • Initial commit