Create a gist now

Instantly share code, notes, and snippets.

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)
hub_.bind(HUB_ADDR)
dealer = ctx.socket(zmq.REP)
dealer.bind(DEALER_ADDR)
while True:
_ = dealer.recv() # reveice worker request
print 'worker ready.'
num = str(num)
dealer.send(num)
print 'worker task sent.'
data = hub_.recv()
print 'worker data recv: ', data
num, ident = loads(data)
print ident, num
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment