Created
April 30, 2013 14:47
-
-
Save esatterwhite/5489209 to your computer and use it in GitHub Desktop.
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
var zmq = require("zmq") | |
var pub = zmq.createSocket("pub") | |
pub.bind("tcp://127.0.0.1:19019"); | |
var x = 0 | |
setInterval(function(){ | |
console.log('publishing') | |
pub.send('foobar ' + ( ++x ) ) | |
},250) |
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
var zmq = require( "zmq" ) | |
, publisher // publisher to redistribute messages over known port | |
, subscriber // subscriber to recieve incomming messaes | |
var xpub_url = process.argv[2] || "tcp://127.0.0.1:19018"; | |
var xsub_url = process.argv[3] || "tcp://127.0.0.1:19019"; | |
subscriber = zmq.createSocket( "xsub", function( err ){ | |
if( err ){ | |
console.log("problem creating xsub on 19019"); | |
console.log( err ) | |
} | |
}) | |
subscriber.bind( xsub_url, function(){ | |
console.log( arguments ) | |
} ) | |
// subscriber.subscribe( "" ) // get all of the messages on this port | |
publisher = zmq.createSocket( "xpub", function( err ){ | |
if( err ){ | |
console.log("problem creating pub socket on 19018 ") | |
console.log( err ) | |
} | |
}) | |
publisher.bind( xpub_url, function(){ | |
console.log( arguments ) | |
} ) | |
publisher.on("message", function( msg ){ | |
console.log("pub writing ", msg.toString(), "to subscriber") | |
subscriber.send( msg ) | |
}) | |
subscriber.on( "message", function( msg ){ | |
console.log("sub writing ", msg.toString(), "to publisher") | |
publisher.send( msg ); | |
}) | |
process.on('SIGINT', function(){ | |
console.log("Shutting down pubsub proxy") | |
process.exit(0) | |
}); |
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
var zmq = require("zmq") | |
var sub = zmq.createSocket("sub") | |
sub.connect("tcp://127.0.0.1:19018"); | |
sub.setsockopt(zmq.ZMQ_SUBSCRIBE, new Buffer( "" ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment