Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (54 sloc) 1.91 KB

ZMQ Poller

In this program, we will create a command server that tells when the worker should exit. Workers subscribes to a topic published by a publisher and prints it. It exits when it receives "Exit" message from the command server.

zmqpolling.py

PUSH server that sends command to workers to continue working or exit.

Publisher that publishes for topics "8","9","10" in random order.

Worker that works on messages received for topic "9". We setup zmq poller to poll for messages on the socket connection to both command server and publisher.

We poll the sockets to check if we have messages to recv and work on it. Worker continues working until it receives exit condition.

Finally, we fire up all the processes.

Output of the program:

Running server on port:  5556
Running server on port:  5558
8 server#2739
Connected to server with port 5556
Connected to publisher with port 5558
Recieved control command: Continue
9 server#2739
Processing ...  9 server#2739
Recieved control command: Continue
9 server#2739
Processing ...  9 server#2739
Recieved control command: Continue
9 server#2739
Processing ...  9 server#2739
Recieved control command: Continue
8 server#2739
Recieved control command: Continue
8 server#2739
Recieved control command: Continue
8 server#2739
Recieved control command: Exit
Recieved exit command, client will stop recieving messages
8 server#2739
9 server#2739
8 server#2739