-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if worker there is identity available
- Loading branch information
Showing
1 changed file
with
16 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
|
||
|