Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zmq

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zmq - npm Package Compare versions

Comparing version 2.11.1 to 2.12.0

appveyor.yml

11

History.md

@@ -0,1 +1,12 @@

2.12.0 / 2015-07-10
===================
* Massive improvements to monitoring code, with new documentation and tests [ValYouW]
* Improved documentation [reqshark]
* Updated bindings from ~1.1.1 to ~1.2.1 [reqshark]
* Test suite improvements [reqshark]
* Updated the Windows bundle to ZeroMQ 4.0.4 [kkoopa]
* License attribute added to package.json [pdehaan]
2.11.1 / 2015-05-21

@@ -2,0 +13,0 @@ ===================

15

lib/index.js

@@ -22,2 +22,8 @@ /**

/**
* Expose zmq_curve_keypair
*/
exports.curveKeypair = zmq.zmqCurveKeypair;
/**
* Map of socket types.

@@ -405,2 +411,3 @@ */

* @param {Number} timer interval in ms > 0 or Undefined for default
* @param {Number} The maximum number of events to read on each interval, default is 1, use 0 for reading all events
* @return {Socket} for chaining

@@ -410,3 +417,3 @@ * @api public

Socket.prototype.monitor = function(interval) {
Socket.prototype.monitor = function(interval, numOfEvents) {
if (zmq.ZMQ_CAN_MONITOR) {

@@ -419,3 +426,7 @@ var self = this;

this._zmq.monitor(interval);
self._zmq.onMonitorError = function(error) {
self.emit('monitor_error', error);
}
this._zmq.monitor(interval, numOfEvents);
} else {

@@ -422,0 +433,0 @@ throw new Error('Monitoring support disabled check zmq version is > 3.2.1 and recompile this addon');

10

package.json
{
"name": "zmq",
"version": "2.11.1",
"version": "2.12.0",
"description": "Bindings for node.js and io.js to ZeroMQ",

@@ -12,3 +12,3 @@ "main": "index",

"nan": "~1.8.4",
"bindings": "~1.1.1"
"bindings": "~1.2.1"
},

@@ -24,5 +24,6 @@ "devDependencies": {

"scripts": {
"test": "make test"
"test": "mocha --expose-gc --slow 2000 --timeout 600000"
},
"keywords": ["zeromq", "zmq", "0mq", "ømq", "libzmq", "native", "binding", "addon"],
"license": "MIT",
"author": "Justin Tulloss <justin.tulloss@gmail.com> (http://justin.harmonize.fm)",

@@ -59,4 +60,5 @@ "contributors": [

"Alejandro (https://github.com/Minjung)",
"Eli Skeggs <skeggse@gmail.com> (https://github.com/skeggse)"
"Eli Skeggs <skeggse@gmail.com> (https://github.com/skeggse)",
"Bent Cardan <bent@nothingsatisfies.com> (https://github.com/reqshark)"
]
}

@@ -1,10 +0,22 @@

[![Build Status](https://travis-ci.org/JustinTulloss/zeromq.node.png)](https://travis-ci.org/JustinTulloss/zeromq.node)
# zmq &nbsp;&nbsp;[![Build Status](https://travis-ci.org/JustinTulloss/zeromq.node.png)](https://travis-ci.org/JustinTulloss/zeromq.node) &nbsp;[![Build status](https://ci.appveyor.com/api/projects/status/n0h0sjs127eadfuo/branch/windowsbuild?svg=true)](https://ci.appveyor.com/project/reqshark/zeromq-node)
# node-zeromq
[ØMQ](http://www.zeromq.org/) bindings for node.js.
[ØMQ](http://www.zeromq.org/) bindings for node.js.
## Installation
First make sure [ZeroMQ is installed](http://www.zeromq.org/intro:get-the-software).
### on Windows:
First install [Visual Studio](https://www.visualstudio.com/) and either
[Node.js](https://nodejs.org/download/) or [io.js](https://iojs.org/dist/latest/).
Ensure you're building zmq from a conservative location on disk, one without
unusual characters or spaces, for example somewhere like: `C:\sources\myproject`.
Installing the ZeroMQ library is optional and not required on Windows. We
recommend running `npm install` and node executable commands from a
[github for windows](https://windows.github.com/) shell or similar environment.
### installing on Unix/POSIX (and osx):
First install `pkg-config` and the [ZeroMQ library](http://www.zeromq.org/intro:get-the-software).
This module is compatible with ZeroMQ versions 2, 3 and 4. The installation

@@ -21,6 +33,6 @@ process varies by platform, but headers are mandatory. Most Linux distributions

Note: For zap support with versions >=4 you need to have libzmq built and linked
against libsodium. Check the Travis configuration for a list of what is tested
against libsodium. Check the [Travis configuration](.travis.yml) for a list of what is tested
and therefore known to work.
With ZeroMQ headers installed, you can install and use this module:
#### with your platform-specifics taken care of, install and use this module:

@@ -89,17 +101,93 @@ $ npm install zmq

```
## Monitoring
## Running tests
You can get socket state changes events by calling to the `monitor` function.
The supported events are (see ZMQ [docs](http://api.zeromq.org/4-2:zmq-socket-monitor) for full description):
* connect - ZMQ_EVENT_CONNECTED
* connect_delay - ZMQ_EVENT_CONNECT_DELAYED
* connect_retry - ZMQ_EVENT_CONNECT_RETRIED
* listen - ZMQ_EVENT_LISTENING
* bind_error - ZMQ_EVENT_BIND_FAILED
* accept - ZMQ_EVENT_ACCEPTED
* accept_error - ZMQ_EVENT_ACCEPT_FAILED
* close - ZMQ_EVENT_CLOSED
* close_error - ZMQ_EVENT_CLOSE_FAILED
* disconnect - ZMQ_EVENT_DISCONNECTED
Install dev deps:
All events get 2 arguments:
* fd - The file descriptor of the underlying socket (if available)
* endpoint - The underlying socket endpoint
$ npm install
A special `monitor_error` event will be raised when there was an error in the monitoring process, after this event no more
monitoring events will be sent, you can try and call `monitor` again to restart the monitoring process.
Build:
### monitor(interval, numOfEvents)
Will create an inproc PAIR socket where zmq will publish socket state changes events, the events from this socket will
be read every `interval` (defaults to 10ms).
By default only 1 message will be read every interval, this can be configured by using the `numOfEvents` parameter,
where passing 0 will read all available messages per interval.
$ make
### unmonitor()
Stop the monitoring process
Test:
### example
$ make test
```js
// Create a socket
var zmq = require('zmq');
socket = zmq.socket('req');
// Register to monitoring events
socket.on('connect', function(fd, ep) {console.log('connect, endpoint:', ep);});
socket.on('connect_delay', function(fd, ep) {console.log('connect_delay, endpoint:', ep);});
socket.on('connect_retry', function(fd, ep) {console.log('connect_retry, endpoint:', ep);});
socket.on('listen', function(fd, ep) {console.log('listen, endpoint:', ep);});
socket.on('bind_error', function(fd, ep) {console.log('bind_error, endpoint:', ep);});
socket.on('accept', function(fd, ep) {console.log('accept, endpoint:', ep);});
socket.on('accept_error', function(fd, ep) {console.log('accept_error, endpoint:', ep);});
socket.on('close', function(fd, ep) {console.log('close, endpoint:', ep);});
socket.on('close_error', function(fd, ep) {console.log('close_error, endpoint:', ep);});
socket.on('disconnect', function(fd, ep) {console.log('disconnect, endpoint:', ep);});
// Handle monitor error
socket.on('monitor_error', function(err) {
console.log('Error in monitoring: %s, will restart monitoring in 5 seconds', err);
setTimeout(function() { socket.monitor(500, 0); }, 5000);
});
// Call monitor, check for events every 500ms and get all available events.
console.log('Start monitoring...');
socket.monitor(500, 0);
socket.connect('tcp://127.0.0.1:1234');
setTimeout(function() {
console.log('Stop the monitoring...');
socket.unmonitor();
}, 20000);
```
## Running tests
#### Install dev deps:
```sh
$ git clone https://github.com/JustinTulloss/zeromq.node.git zmq && cd zmq
$ npm i
```
#### Build:
```sh
# on unix:
$ make
# building on windows:
> npm i
```
#### Test:
```sh
# on unix:
$ make test
# testing on windows:
> npm t
```
## Running benchmarks

@@ -139,2 +227,1 @@

Running `make perf` will run the commands listed above.

@@ -25,8 +25,9 @@ var zmq = require('..')

}
var currMaxSockets = zmq.Context.getMaxSockets();
zmq.Context.setMaxSockets(256);
zmq.Context.getMaxSockets().should.equal(256);
zmq.Context.setMaxSockets(1024);
zmq.Context.setMaxSockets(currMaxSockets);
done();
});
});
});

@@ -11,2 +11,16 @@

it('should generate valid curve keypair', function(done) {
if (!semver.gte(zmq.version,'4.0.0') || require('os').platform() == 'win32'){
done();
return console.warn('Test requires libzmq >= 4 compiled with libsodium');
}
var curve = zmq.curveKeypair();
should.exist(curve);
should.exist(curve.public);
should.exist(curve.secret);
curve.public.length.should.equal(40);
curve.secret.length.should.equal(40);
done();
});
it('should export socket types and options', function(){

@@ -13,0 +27,0 @@ // All versions.

@@ -5,11 +5,9 @@ var zmq = require('..')

describe('socket.monitor', function(){
it('should be able to monitor the socket', function(done){
/* no test if monitor is not available */
if (!zmq.ZMQ_CAN_MONITOR) {
console.log("monitoring not enabled skipping test");
done();
return;
}
describe('socket.monitor', function() {
if (!zmq.ZMQ_CAN_MONITOR) {
console.log("monitoring not enabled skipping test");
return;
}
it('should be able to monitor the socket', function(done) {
var rep = zmq.socket('rep')

@@ -25,22 +23,22 @@ , req = zmq.socket('req')

rep.on('listen', function(event_value, event_endpoint_addr){
console.log("listen %s,%d",event_endpoint_addr,event_value);
event_endpoint_addr.toString().should.equal('tcp://127.0.0.1:5423');
events.push('listen');
});
var testedEvents = ['listen', 'accept', 'disconnect', 'close'];
testedEvents.forEach(function(e) {
rep.on(e, function(event_value, event_endpoint_addr) {
// Test the endpoint addr arg
event_endpoint_addr.toString().should.equal('tcp://127.0.0.1:5423');
rep.on('accept', function(event_value, event_endpoint_addr){
console.log("accept %s,%d",event_endpoint_addr,event_value);
event_endpoint_addr.toString().should.equal('tcp://127.0.0.1:5423');
events.push('accept');
});
// If this is a disconnect event we can now close the rep socket
if (e === 'disconnect') {
rep.close();
}
rep.on('disconnect', function(event_value, event_endpoint_addr){
console.log("disconnect %s,%d",event_endpoint_addr, event_value);
event_endpoint_addr.toString().should.equal('tcp://127.0.0.1:5423');
events.push('disconnect');
events.length.should.equal(3);
testedEvents.pop();
if (testedEvents.length === 0) {
rep.unmonitor();
done();
}
});
});
/* enable monitoring for this socket */
// enable monitoring for this socket
rep.monitor();

@@ -57,10 +55,2 @@

req.close();
rep.close();
/* wait a few for the close to reach us then
* unmonitor to release the handle
*/
setTimeout((function() {
rep.unmonitor();
done();
}), 500);
});

@@ -70,2 +60,49 @@ });

it('should use default interval and numOfEvents', function(done) {
var req = zmq.socket('req');
req.setsockopt(zmq.ZMQ_RECONNECT_IVL, 5); // We want a quick connect retry from zmq
// We will try to connect to a non-existing server, zmq will issue events: "connect_retry", "close", "connect_retry"
// The connect_retry will be issued immediately after the close event, so we will measure the time between the close
// event and connect_retry event, those should >= 10 (this will tell us that we are reading 1 event at a time from
// the monitor socket).
var closeTime;
req.on('close', function() {
closeTime = Date.now();
});
req.on('connect_retry', function() {
var diff = Date.now() - closeTime;
req.unmonitor();
req.close();
diff.should.be.within(10, 20);
done();
});
req.monitor();
req.connect('tcp://127.0.0.1:5423');
});
it('should read multiple events on monitor interval', function(done) {
var req = zmq.socket('req');
req.setsockopt(zmq.ZMQ_RECONNECT_IVL, 5);
var closeTime;
req.on('close', function() {
closeTime = Date.now();
});
req.on('connect_retry', function() {
var diff = Date.now() - closeTime;
req.unmonitor();
req.close();
diff.should.be.within(0, 5);
done();
});
// This should read all available messages from the queue, and we expect that "close" and "connect_retry" will be
// read on the same interval (for further details see the comment in the previous test)
req.monitor(10, 0);
req.connect('tcp://127.0.0.1:5423');
});
});

@@ -20,2 +20,4 @@ var zmq = require('..')

var envelope = '12384982398293';
var errMsg = 'No route to host';
if (require('os').platform() == 'win32') errMsg = 'Unknown error';

@@ -27,3 +29,3 @@ // should emit an error event on unroutable msgs if mandatory = 1 and error handler is set

sock.on('error', function(err){
err.message.should.equal('No route to host');
err.message.should.equal(errMsg);
sock.close();

@@ -47,11 +49,11 @@ if (++complete === 2) done();

sock.send([envelope, '']);
}).should.throw('No route to host');
}).should.throw(errMsg);
(function(){
sock.send([envelope, '']);
}).should.throw('No route to host');
}).should.throw(errMsg);
(function(){
sock.send([envelope, '']);
}).should.throw('No route to host');
}).should.throw(errMsg);

@@ -69,3 +71,3 @@ sock.close();

sock.close();
}).should.not.throw('No route to host');
}).should.not.throw(errMsg);
})();

@@ -72,0 +74,0 @@ if (++complete === 2) done();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc