Reputation: 6168
I am using zeromq in the web analytics to have a real time notification of log.
Details: I am reading the log file (web analytics log file). Whenever the log file modified,it is to be read. It is same as the tail in ubuntu. I am using zeromq for pub-sub event.
sample server side:
var zmq = require('zmq');
var socket = zmq.socket('pub');
socket.bind('tcp://127.0.0.1:2001', function(error) {
if (error) {
console.log(error);
}
var fs = require("fs");
fs.watchFile(config.filePath, function (curr, prev) {
socket.send("file updated");
});
var socket = zmq.socket('sub');//Have to be ported to client side
socket.connect('tcp://127.0.0.1:2001');
socket.subscribe('');
socket.on('message', function(msg){
console.log('work: %s', msg);
});
});
My question is how to listen the event in the client side (javascript) and how to require zmq in client side?
I am new to zeromq. Any help will be greatful.
Upvotes: 1
Views: 2638
Reputation: 12065
This may not relate to your question, but I figured I would add this in case anyone else is having issues getting the examples from ØMQ or the zguide.
If you are running a server-client example from this page (or a similar example set from the language of your choice):
http://zguide.zeromq.org/js:_start
and it's not working, then try checking out this page:
https://github.com/imatix/zguide/tree/master/examples
and try one of the examples in the language of your choice. This helped me immensely and the examples (so far) have worked on the first attempt!
Upvotes: 1
Reputation: 32066
Lots of client examples in node.js here...
https://github.com/imatix/zguide/tree/master/examples/Node.js
Why do you have subscriber code on the server? Is this just a sanity check?
var socket = zmq.socket('sub');
socket.connect('tcp://127.0.0.1:2001');
socket.subscribe('');
socket.on('message', function(msg){
console.log('work: %s', msg);
});
Upvotes: 1