Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Created June 6, 2020 05:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timothymugayi/27cb2a09ed6c390629e9798371125d9f to your computer and use it in GitHub Desktop.
Save timothymugayi/27cb2a09ed6c390629e9798371125d9f to your computer and use it in GitHub Desktop.
# Subscribers are created with ZMQ.SUB socket types.
# A zmq subscriber can connect to many publishers.
import sys
import zmq
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Collecting updates from server...")
socket.connect("tcp://localhost:%s" % port)
# Subscribes to all topics you can selectively create multiple workers
# that would be responsible for reading from one or more predefined topics
# if you have used AWS SNS this is a simliar concept
socket.subscribe("")
while True:
# Receives a string format message
print(socket.recv())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment