-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (30 loc) · 1017 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var zmq = require('zmq');
module.exports = exports = (function zmqTransport () {
function zmqTransport(params) {
this.params = params;
if (!this.params) {
throw new Error('emptyParams');
}
}
zmqTransport.prototype.send = function (body, callback) {
var socket;
socket = zmq.socket('req');
socket.connect(this.params.url);
socket.send(JSON.stringify(body));
return socket.on('message', function (data) {
return callback(null, data);
});
};
zmqTransport.prototype.listen = function (server) {
var socket;
socket = zmq.socket('rep');
return socket.bind(this.params.url, function (err) {
return socket.on('message', function (data) {
return server.handleCall(data.toString(), {}, function (answer) {
return socket.send(JSON.stringify(answer));
});
});
});
};
return zmqTransport;
})();