Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/0rpc/zerorpc-node
- Owner: 0rpc
- License: other
- Created: 2012-05-31T01:17:30.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-04-16T07:07:07.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T01:03:07.456Z (3 months ago)
- Language: JavaScript
- Homepage: http://www.zerorpc.io
- Size: 417 KB
- Stars: 706
- Watchers: 39
- Forks: 166
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - 0rpc/zerorpc-node - zerorpc for node.js (JavaScript)
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