Skip to content

Instantly share code, notes, and snippets.

@petrushev petrushev/
Created Jun 10, 2012

What would you like to do?
[nsnd struga] Simple hub/worker architecture
import zmq
from json import loads, dumps
HUB_ADDR = 'tcp://*:5555'
DEALER_ADDR = 'tcp://*:5566'
def main():
num = 1
ctx = zmq.Context()
hub_ = ctx.socket(zmq.PULL)
dealer = ctx.socket(zmq.REP)
while True:
_ = dealer.recv() # reveice worker request
print 'worker ready.'
num = str(num)
print 'worker task sent.'
data = hub_.recv()
print 'worker data recv: ', data
num, ident = loads(data)
print ident, num
if __name__=='__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.