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

redis-rpc

v0.0.6

Published

A module to write microservices with Node.js. Abstracts remote procedure call from one node server to other using redis pub/sub.

Downloads

9

Readme

redis-rpc

A module to write microservices with Node.js Abstracts remote procedure call from one node server to other using redis pub/sub.

Before You Begin

What it Does?

Lets assume you have a application made of two node servers.

  • A dispatcher server which handles users and routes.
  • A service module that performs backend tasks.
  1. This module will make a call from dispatcher module to service module.
  2. Service module will then perform the task.
  3. Once task is completed service module will send data to the dispatcher module which will then call a callback for that task.

Pre-requisites

A redis server should be up and running on the machine.

Usage

Install

npm install redis-rpc

Initialiize

var redis       = require("redis");  
var redisRPCLib = require("redis-rpc");  
var redisRPC    = new redisRPCLib(/\*options/\*);   

Options

pub         : a redis client to publish data to.(Default : creates a redis client)
sub         : a redis client to get data from.(Default : creates a redis client)
pubModule*  : redis channel to publish data to. 
subModule*  : redis channel to get data from.
dispatcher  : boolean to tell if this a dispatcher or service module(Default : true)
tasks       : an object containing functions for service module or calls for callbacks for dispatcher module
pubError    : Function called if any error occurs while publishing
subError    : Function called if any error occurs on a message from subscribed channel
argSep      : a string to separate argument name and value groups
keyValSep   : a string to separate argument's name and value

Example

Assumptions

There are 2 node servers running

  1. Dispatcher Server
  2. Service Server

Dispatcher server wants to call a function "Add" on Service Server.

Code

Dispatcher Server

var redisRPCLib = require("redis-rpc");

var redisRPC = new redisRPCLib({
    subModule : "dispatcher",    // Dispatcher will listen for data on dispatcher channel
    pubModule : "service",       // Service will listen for data on service channel    
    tasks     : {               // Callback functions for each task. 
                                //*Task and callback name should be same*            
        //Callback to call once service finishes Adding            
        Add : function(err,result){
            if(err){
                return console.log(err);
            }
            console.log("Addition result : ",result);
        }
    },
    dispatcher  : true          // Telling redis-rpc that this is a 
                                // dispatcher and task results do not need to be published 
});

//Make Call

redisRPC.sendCall({
    task : "Add",
    args : [1, 2]
});

Service Server

var redisRPCLib = require("redis-rpc");
 
var redisRPC = new redisRPCLib({
        subModule : "service",      // Service will listen for data on service channel
        pubModule : "dispatcher",   // Dispatcher will listen for data on dispatcher channel    
        tasks     : {               // functions for each task. 
                                    //*Task and callback name should be same*                
            //Function to add                
            Add : function(a,b,done){           //Redis-RPC will always pass the last argument as callback
                done(a+b);
            }
        },
        dispatcher  : false          // Telling redis-rpc that this is not a 
                                    // dispatcher and task results need to be published 
    });
    

sendCall Function

It only takes one object argument with following properties.

task*           : Name of the task
args*           : An array of arguments
argTypes        : An array of argument data types (only supported are ["object","array","date","string","number","null"]). 
sessionId       : A sessionId which will be automatically added as the last argument to callback on dispatcher.          
     

echo Function

This function will send data from dispatcher to service and console.log it on return.

To Do

  • Add support for boolean types
  • Add tasks after initialization
  • Add support for echo callback function