Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2012 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/2132163 to your computer and use it in GitHub Desktop.
Save anonymous/2132163 to your computer and use it in GitHub Desktop.
ZMQ Forwarder
import zmq
import signal
# this method handles the termination of the app
# this handler is responsible for properly cleaning of the ports
def termSignalHandler(signum,frame):
incoming.close()
outgoing.close()
context.term()
print("termSignal Handler Called")
def startForwarder():
context = zmq.Context(1)
incoming = context.socket(zmq.SUB)
outgoing = context.socket(zmq.PUB)
try:
incoming.connect("tcp://127.0.0.1:5559");
incoming.setsockopt(zmq.SUBSCRIBE, "")
except:
print("incoming socket is already open")
try:
outgoing.bind('tcp://127.0.0.1:4449')
except:
print("outgoing socket is open")
zmq.device(zmq.FORWARDER, incoming, outgoing)
signal.signal(signal.SIGTERM,termSignalHandler)
startForwarder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment