Created
March 20, 2012 06:56
-
-
Save anonymous/2132163 to your computer and use it in GitHub Desktop.
ZMQ Forwarder
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
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