Last active
May 27, 2017 20:20
-
-
Save abuzarhamza/adb137699b332b13cfe2dbe8d04ebb4c to your computer and use it in GitHub Desktop.
zmq-publisher.js
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
const fs = require('fs'), | |
zmq = require('/usr/local/lib/node_modules/zmq'), | |
filename = 'pub.txt'; | |
const pub = zmq.socket('pub'); | |
//watch the change in the file. | |
//when you want to sned the message make change in pub.txt | |
fs.watch(filename, function() { | |
//message send to subscriber with cat | |
pub.send( [ 'cat' , JSON.stringify({ | |
type: 'change', | |
file: filename, | |
time: Date.now() | |
}) | |
]); | |
//message send to subscriber with dog | |
setTimeout( function () { | |
pub.send(['dog' ,JSON.stringify({ | |
type: 'change', | |
file: filename, | |
time: Date.now() | |
}) | |
]); | |
} , 10000) | |
}); | |
pub.bind('tcp://*:3000', function() { | |
console.log("Publisher listening to port 3000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment