Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created August 21, 2010 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvc/542709 to your computer and use it in GitHub Desktop.
Save andrewvc/542709 to your computer and use it in GitHub Desktop.
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