Created
August 21, 2010 19:08
-
-
Save andrewvc/542709 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
DripDrop::Node.new do |node| | |
### | |
### ZMQ Forwarder | |
### | |
fwd_pub = node.zmq_publish(FORWARDER_OUT) | |
node.zmq_subscribe(FORWARDER_IN,:socket_ctype => :bind).on_recv_raw do |message| | |
fwd_pub.send_message(message) | |
print 'f' | |
end | |
### | |
### Persist all data to a MongoDB Instance | |
### | |
db = EM::Mongo::Connection.new.db('dripdrop') | |
collection = db.collection('stats') | |
node.zmq_subscribe(FORWARDER_OUT).on_recv do |message| | |
hash = collection.insert(Hash.new) | |
print 'm' | |
end | |
### | |
### Broadcast a ZMQ sub socket out to web sockets | |
### | |
node.websocket(WEBSOCKET_ADDR).on_open {|ws| | |
#This actually isn't the most efficient way to do this, normally | |
#you'd do one sub socket per process + node.recv_internal, | |
#but this is here for fun | |
node.zmq_subscribe(FORWARDER_OUT).on_recv {|message| | |
print 'w' | |
ws.send(message.to_hash.to_json) | |
} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment