Skip to content

Commit

Permalink
Check if worker there is identity available
Browse files Browse the repository at this point in the history
  • Loading branch information
vicennt committed Dec 9, 2017
1 parent 8b230d2 commit 1841f39
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions myworker.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
// Execution example -> $node myworker.js "tcp://localhost:8060" "Worker1" "Ready" "Done" -v

var zmq = require("zmq");
var resp = zmq.socket("req");
var req = zmq.socket("req");

// Getting atributes from command line arguments
var args = process.argv.slice(2);
var backend_url = args[0] || "tcp://localhost:8060";
var my_id = args[1] || "NONE";
var disp_text = args[2] || "Ready";
var reply_text = args[3] || "Done";

var verbose = false;

if(args[args.length - 1] == "-v"){
verbose = true;
args.pop();
}

resp.indentity = my_id;
resp.connect(backend_url);
if(my_id != "NONE")
req.identity = my_id;

req.connect(backend_url);
req.send(disp_text);

if(verbose){
console.log('Worker (%s) connected to "%s"', my_id, backend_url);
console.log('Worker (%s) has sent its first connection message: "%s"', my_id, disp_text);
}

resp.on("message", function(client, delimiter, msg){
if(verbose){
console.log('Worker (%s) has received request "%s" from client (%s)',
my_id, msg.toString(), client);
}
req.on("message", function(client, delimiter, msg){
if(verbose)
console.log('Worker (%s) has received request ["%s"] from client (%s)', my_id, msg.toString(), client);

setTimeout(function(){
resp.send([client,'',reply_text]);
if(verbose){
req.send([client,'',reply_text]);
if(verbose)
console.log('Worker (%s) has sent its reply "%s"', my_id, reply_text);
}
}, 1000);
});

resp.send(con_text);

if(verbose){
console.log('Worker (%s) has sent its first connection message: "%s"', my_id, disp_text);
}




0 comments on commit 1841f39

Please sign in to comment.