Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroMQ v6 compatibility update #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Events:
Methods:

* `bind(endpoint)` - Binds the server to the specified ZeroMQ endpoint.
Returns `Promise<void>`, which is resolved when the
socket was successfully bound (new in v0.9.9.beta).
* `connect(endpoint)` - Connects the server to the specified ZeroMQ endpoint.
* `close()` - Closes the ZeroMQ socket.

Expand Down Expand Up @@ -100,7 +102,9 @@ Events:

Methods:

* `bind(endpoint)` - Binds the client to the specified ZeroMQ endpoint.
* `bind(endpoint)` - Binds the client to the specified ZeroMQ endpoint. Returns
`Promise<void>`, which is resolved when the socket was
successfully bound (new in v0.9.9.beta).
* `connect(endpoint)` - Connects the client to the specified ZeroMQ endpoint.
* `close()` - Closes the ZeroMQ socket.
* `invoke(method, arguments..., callback)` - Invokes a remote method.
Expand Down
6 changes: 4 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ function Client(options) {

nodeUtil.inherits(Client, events.EventEmitter);

//Binds to a ZeroMQ endpoint
//Binds to a ZeroMQ endpoint (async)
//endpoint : String
// The ZeroMQ endpoint
//return : Promise<void>
// Resolved when the socket was successfully bound.
Client.prototype.bind = function(endpoint) {
this._socket.bind(endpoint);
return this._socket.bind(endpoint);
};

//Connects to a ZeroMQ endpoint
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function serialize(event) {
message = message.concat(event.envelope);
}

message.push(new Buffer(0));
message.push(new Buffer.alloc(0));
message.push(msgpack.encode(payload));
return message;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ Server.prototype._recv = function(event, context) {
}
}

//Binds to a ZeroMQ endpoint
//Binds to a ZeroMQ endpoint (async)
//endpoint : String
// The ZeroMQ endpoint
//return : Promise<void>
// Resolved when the socket was successfully bound.
Server.prototype.bind = function(endpoint) {
this._socket.bind(endpoint);
return this._socket.bind(endpoint);
};

//Connects to a ZeroMQ endpoint
Expand Down
15 changes: 11 additions & 4 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// DEALINGS IN THE SOFTWARE.

var nodeUtil = require("util"),
zmq = require("zeromq"),
zmq = require("zeromq/v5-compat"),
nodeEvents = require("events"),
events = require("./events"),
util = require("./util"),
Expand Down Expand Up @@ -72,12 +72,19 @@ Socket.prototype.send = function(event) {
this._zmqSocket.send.call(this._zmqSocket, message);
};

//Binds to a ZeroMQ endpoint
//Binds to a ZeroMQ endpoint (async)
//endpoint : String
// The ZeroMQ endpoint
//return : Promise<void>
// Resolved when the socket was successfully bound.
Socket.prototype.bind = function(endpoint) {
this._zmqSocket.bindSync(endpoint);
}
return new Promise((resolve, reject) => {
this._zmqSocket.bind(endpoint, err => {
if (err) reject(err);
resolve();
});
});
};

//Connects to a ZeroMQ endpoint
//endpoint : String
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
],
"dependencies": {
"msgpack-lite": "^0.1.26",
"underscore": "1.3.3",
"uuid": "^3.0.0",
"zeromq": "^4.6.0"
"underscore": "^1.9.1",
"uuid": "^3.3.3",
"zeromq": "^6.0.0-beta.3"
},
"devDependencies": {
"nodeunit": "0.9.1",
"temp": "0.8.1"
"nodeunit": "^0.11.3",
"temp": "^0.9.1"
},
"license": "MIT"
}
8 changes: 7 additions & 1 deletion test/buffers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ module.exports = {
reply();
}
});
this.srv.bind(endpoint);
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
})
.catch(err => {
console.error(err);
});
},
tearDown: function(cb) {
this.cli.close();
Expand Down
14 changes: 10 additions & 4 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ module.exports = {
}
});

this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
})
.catch(err => {
console.error(err)
});
},
tearDown: function(cb) {
this.cli.close();
Expand Down
16 changes: 11 additions & 5 deletions test/heartbeats.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ module.exports = {
}, 250);
}
}, heartbeat);
this.srv.bind(endpoint);
this.srv.on('error', function(err) {
//console.log('on error', err);
});
this.cli = new zerorpc.Client({ timeout: 11000, heartbeat: heartbeat });
this.cli.connect(endpoint);
this.killed = false;
cb();
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 11000, heartbeat: heartbeat });
this.cli.connect(endpoint);
this.killed = false;
cb();
})
.catch(err => {
console.error(err)
});
},
tearDown: function(cb) {
if (!this.cli.closed()) {
Expand Down
14 changes: 10 additions & 4 deletions test/invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ module.exports = {
reply(null, n + 42, false);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
})
.catch(err => {
console.error(err)
});
},
tearDown: function(cb) {
this.cli.close();
Expand Down
8 changes: 7 additions & 1 deletion test/repro-10.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ module.exports = {
}
});

srv.bind(endpoint);
srv
.bind(endpoint)
.then(() => {
cli = new zerorpc.Client({ timeout: 5 });

setTimeout(function() {
Expand All @@ -49,5 +51,9 @@ module.exports = {
test.done();
});
}, 10000);
})
.catch(err => {
console.error(err)
});
}
};
14 changes: 10 additions & 4 deletions test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ module.exports = {
}, 1000);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
})
.catch(err => {
console.error(err)
});
},
tearDown: function(cb) {
this.cli.close();
Expand Down
14 changes: 10 additions & 4 deletions test/timeouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ module.exports = {
}, 6 * 1000);
}
});
this.srv.bind(endpoint);
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
this.srv
.bind(endpoint)
.then(() => {
this.cli = new zerorpc.Client({ timeout: 5 });
this.cli.connect(endpoint);
cb();
})
.catch(err => {
console.error(err)
});
},
tearDown: function(cb) {
this.cli.close();
Expand Down