Skip to content

Instantly share code, notes, and snippets.

@commandodev
Created April 21, 2011 10:23
Show Gist options
  • Save commandodev/934112 to your computer and use it in GitHub Desktop.
Save commandodev/934112 to your computer and use it in GitHub Desktop.
class Component(object):
def _setup_sockets(self):
pub_address = "tcp://whatever..."
ext_socket = ctx.socket(zmq.PUB)
ext_socket.bind(pub_address)
self.internal_addr = "inproc://my_pub"
int_socket = ctx.socket(zmq.PULL)
int_socket.bind(self.internal_addr)
eventlet.spawn_n(self.forward_messages, int_socket, ext_socket)
def forward_messages(self, internal, external):
while True:
external.send(internal.recv())
def create_internal_socket(self):
pusher = ctx.socket(zmq.PUSH)
pusher.connect(self.internal_addr)
return pusher
component = Component()
eventlet.spawn_n(something_that_wants_to_publish, component.create_internal_socket())
eventlet.spawn_n(something_else_that_wants_to_publish, component.create_internal_socket())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment