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

nats-node-rpc

v0.1.3

Published

Fast nodejs RPC library based on nats

Downloads

4

Readme

nats-node-rpc

fast nodejs rpc library based on nats

Benchmark

two node process: benchmark_s and benchmark_c on local machine
CPU: intel 4790K

testString 1 sequence start
testString 1 sequence finished, count = 100000, time = 7994ms, speed = 12509/s
testJson 1 sequence start
testJson 1 sequence finished, count = 100000, time = 9059ms, speed = 11039/s
testString 100 sequence start
testString 100 sequence finished, count = 100000, time = 691ms, speed = 144718/s
testJson 100 sequence start
testJson 100 sequence finished, count = 100000, time = 894ms, speed = 111857/s

Features

Normally you should use Partial Rpc

*Topic

A Topic is RPC interface name for both client and server.

Partial Rpc

Servers A, B, C ... N, can register to the same Topic. But only one server will receive client request, then handle it reply to client. It is always 1 to 1.

*Full RPC

Servers A, B, C ... N, can register to the same Topic. When client call Topic, all server will receive the request. But only first response(the fastest one) will be used for client.

all server still handle the request, just first response(the fastest one) will be handle by client.

you should only has one Full RPC handler server, others should be Full Push handler servers

*Push and Partial Push

Like Full RPC and Partial Rpc, but on return data.

*QueryCallback and Query

Unlike RPC only first response is valid. All response will be available to QueryCallback.

Example: you can use 4 servers register Full RPC to Topic: ServerStatus. 1 monitor server register QueryCallback to Topic: ServerStatus, call Query on timer, then the monitor server will receive 4 status reports on each timer.

*Partial Named Rpc

Advanced Partial Rpc, named group servers only one server will get request. eg: 4 named group with total 20 servers, only 4 servers will receive request.

Install

npm install nats-node-rpc

Tests

cd test
wget https://github.com/nats-io/gnatsd/releases/download/v0.9.4/gnatsd-v0.9.4-linux-amd64.zip
unzip gnatsd-v0.9.4-linux-amd64.zip
nohup ./gnatsd-v0.9.4-linux-amd64/gnatsd > /dev/null 2>&1 &
node simple
node partialRpc
node xxx

sample

var natsLib, natsRpc, natsServers, clientA, clientB, clientC, clientTest;
natsLib = require("nats-node-rpc");
natsRpc = new natsLib;
natsServers = ['nats://127.0.0.1:4222', 'nats://127.0.0.1:5222'];
clientA = natsRpc.Create(natsServers, "clientA", function(){
  console.log("[clientA]-->[init] >>> connected to nats");
  clientA.RegisterRpcHandlerPartial("testFn", function(topic, msg, cb){
    console.log("[clientA]-->[testFn] >>> msg = ", msg);
    return cb(null, "hello from clientA");
  });
});
clientB = natsRpc.Create(natsServers, "clientB", function(){
  console.log("[clientB]-->[init] >>> connected to nats");
  clientB.RegisterRpcHandlerPartial("testFn", function(topic, msg, cb){
    console.log("[clientB]-->[testFn] >>> msg = ", msg);
    return cb(null, "hello from clientB");
  });
});
clientC = natsRpc.Create(natsServers, "clientC", function(){
  console.log("[clientC]-->[init] >>> connected to nats");
  clientC.RegisterRpcHandlerPartial("testFn", function(topic, msg, cb){
    console.log("[clientC]-->[testFn] >>> msg = ", msg);
    return cb(null, "hello from clientC");
  });
});
clientTest = natsRpc.Create(natsServers, "clientTest", function(){
  console.log("[clientTest]-->[init] >>> connected to nats");
  setTimeout(function(){
    var i$, i;
    for (i$ = 0; i$ < 10; ++i$) {
      i = i$;
      clientTest.RpcAsync("testFn", "hi from clientTest n = " + i, fn$);
    }
    function fn$(err, ret){
      console.log("[clientTest]-->[after testFn] >>> ret = ", ret);
    }
  }, 1000);
});