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

async-pomelo-rpc

v1.0.7

Published

pomelo-rpc is the low level RPC framework for pomelo project. It contains two parts: client and server.

Downloads

3

Readme

#pomelo-rpc - rpc framework for pomelo

pomelo-rpc is the low level RPC framework for pomelo project. It contains two parts: client and server.

The client part generates the RPC client proxy, routes the message to the appropriate remote server and manages the network communications. Support add proxies and remote server information dynamically.

The server part exports the remote services, dispatches the remote requests to the services and also manages the network communications.

And the remote service codes would loaded by pomelo-loader module and more details please access this link.

  • Tags: node.js

##Installation

npm install pomelo-rpc

##Usage ###Server

var Server = require('pomelo-rpc').server;

// remote service path info list
var paths = [
  {namespace: 'user', path: __dirname + '/remote/test'}
];

var port = 3333;

var server = Server.create({paths: paths, port: port});
server.start();
console.log('rpc server started.');

###Client

var Client = require('pomelo-rpc').client;

// remote service interface path info list
var records = [
  {namespace: 'user', serverType: 'test', path: __dirname + '/remote/test'}
];

// server info list
var servers = [
  {id: 'test-server-1', serverType: 'test', host: '127.0.0.1', port: 3333}
];

// route parameter passed to route function
var routeParam = null;

// route context passed to route function
var routeContext = servers;

// route function to caculate the remote server id
var routeFunc = function(routeParam, msg, routeContext, cb) {
  cb(null, routeContext[0].id);
};

var client = Client.create({routeContext: routeContext, router: routeFunc});

client.start(function(err) {
  console.log('rpc client start ok.');

  client.addProxies(records);
  client.addServers(servers);

  client.proxies.user.test.service.echo(routeParam, 'hello', function(err, resp) {
    if(err) {
      console.error(err.stack);
    }
    console.log(resp);
  });
});

##Server API ###Server.create(opts) Create a RPC server instance. Intitiate the instance and acceptor with the configure. ###Parameters

  • opts.port - rpc server listening port.
  • opts.paths - remote service path infos, format: [{namespace: remote service namespace, path: remote service path}, ...].
  • opts.context - remote service context.
  • opts.acceptorFactory(opts, msgCB) - (optional) acceptor factory method. opts.port:port that acceptor would listen,opts.services:loaded remote services,format: {namespace: {name: service}}. msgCB(msg, cb): remote request arrived callback. the method should return a acceptor instance.

###server.start Start the remote server instance.

###server.stop Stop the remote server instance and the acceptor.

###Acceptor Implement the low level network communication with specified protocol. Customize the protocol by passing an acceptorFactory to return different acceptors.

###acceptor.listen(port) Listen the specified port.

###acceptor.close Stop the acceptor.

##Client API ###Client.create(opts) Create an RPC client instance which would generate proxies for the RPC client. ####Parameters

  • opts.context - context for mailbox.
  • opts.routeContext - (optional)context for route function.
  • opts.router(routeParam, msg, routeContext, cb) - (optional) route function which decides the RPC message should be send to which remote server. routeParam: route parameter, msg: RPC descriptioin message, routeContext: opts.routeContext.
  • opts.mailBoxFactory(serverInfo, opts) - (optional) mail box factory method.

###client.addProxies(records) Load new proxy codes. ####Parameters

  • records - new proxy code configure information list。Format: [{namespace: service_name_space, serverType: remote_server_type, path: path_to_remote_service_interfaces}];

###client.addServers(servers) Add new remote server informations. ####Parameters

  • servers - remote server information list. Format: [{id: remote_server_id, serverType: remote_server_type, host: remote_server_host, port: remote_server_port}]

###client.start(cb) Start the RPC client.

###client.stop Stop the RPC client and stop all the mail box connections to remote servers.

###client.rpcInvoke(serverId, msg, cb) Invoke an RPC request. ####Parameters

  • serverId - remote server id.
  • msg - RPC description message. format: {namespace: remote service namespace, serverType: remote server type, service: remote service name, method: remote service method name, args: remote service args}.
  • cb - remote service callback function.

###MailBox Implement the low level network communication with remote server. A mail box instance stands for a remote server. Customize the protocol by passing a mailBoxFactory parameter to client to return different mail box instances.

###mailbox.connect(cb) Connect to the remote server.

###mailbox.close Close mail box instance and disconnect with the remote server.

###mailbox.send(msg, opts, cb) Send the RPC message to the associated remote server. ####Parameters

  • msg - RPC description message, see also clienet.rpcInvoke.
  • opts - reserved.
  • cb - RPC callback function.