Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Created June 6, 2020 05:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothymugayi/7a9c1998f41f4ae6c515e3fafec4c476 to your computer and use it in GitHub Desktop.
Save timothymugayi/7a9c1998f41f4ae6c515e3fafec4c476 to your computer and use it in GitHub Desktop.
# Publishers are created with ZMQ.PUB socket types
# Data is published along with a topic.The subscribers usually
# sets a filter on these topics for topic of their interests.
# A publisher has no connected subscribers, then it will simply drop all messages.
# If you’re using TCP, and a subscriber is slow, messages will queue up on the publisher.
# In the current versions of ØMQ, filtering happens at the subscriber side, not the publisher side.
import zmq
import random
import sys
import time
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:%s" % port)
while True:
topic = random.randrange(9999,10005)
messagedata = random.randrange(1,215) - 80
print("%d %d" % (topic, messagedata))
socket.send(b"%d %d" % (topic, messagedata))
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment