Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/0rpc/zerorpc-node

zerorpc for node.js
https://github.com/0rpc/zerorpc-node

Last synced: 6 days ago
JSON representation

zerorpc for node.js

Awesome Lists containing this project

README

        

zerorpc-node
============

[![Build Status](https://travis-ci.org/0rpc/zerorpc-node.svg?branch=master)](https://travis-ci.org/0rpc/zerorpc-node)

ZeroRPC is a communication layer for distributed systems. zerorpc-node is a port of the original [ZeroRPC](https://github.com/0rpc/zerorpc-python) for node.js. We have full client and server support for version 3 of the protocol, and clients/servers written in the Python version can communicate transparently with those written in node.js. This project is in alpha.

To install the package:

Make sure you have [ZeroMQ](https://github.com/zeromq/libzmq) installed.

Then:

```bash
npm install zerorpc
```

If you get the error `Package libzmq was not found` after making sure ZeroMQ is installed, take a look at [the fix for zeromq.node](https://github.com/JustinTulloss/zeromq.node/issues/55). If you get the error `Unable to load shared library <>/binding.node`, [make sure you run ldconfig](https://github.com/JustinTulloss/zeromq.node/issues/85). If that still doesn't work, check out [this ticket](https://github.com/JustinTulloss/zeromq.node/issues/92).

Servers
-------

To create a new server:

```js
var zerorpc = require("zerorpc");
var server = new zerorpc.Server(context [, heartbeat]);
```

The constructor takes in a context object with the functions to expose
over RPC. Only functions that do not have a leading underscore will be
exposed. Each exposed method must take in a callback as the last
argument. This callback is called as `callback(error, response, more)`
when there is a new update, where error is an error object or string,
response is the new update, and more is a boolean specifying whether new
updates will be available later. `error`, `response`, and `more` default
to falsy values, so e.g. simply calling `callback()` closes an open
stream, since `more` is false by default. Constructor also takes a
heartbeat parameter that specifies the interval that the server should
ping clients to let them know it is active.

Events:

* `error` - When an error occurs.

Methods:

* `bind(endpoint)` - Binds the server to the specified ZeroMQ endpoint.
* `connect(endpoint)` - Connects the server to the specified ZeroMQ endpoint.
* `close()` - Closes the ZeroMQ socket.

Full example:

```js
var zerorpc = require("zerorpc");

var server = new zerorpc.Server({
addMan: function(sentence, reply) {
reply(null, sentence + ", man!");
},

add42: function(n, reply) {
reply(null, n + 42);
},

iter: function(from, to, step, reply) {
for(i=from; i