You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I want a simple queueing service from NATS where my publisher can keep on putting messages in the queue and they persist unless they are acknowledged. I tried following the example on the following link and made 2 different files. One for subscriber and other for publisher but it doesn't work as expected. I only see one message instead of three.
publisher.py
importosimportasyncioimportnatsfromnats.errorsimportTimeoutErrorservers=os.environ.get("NATS_URL", "nats://localhost:4222").split(",")
asyncdefmain():
# Create the connection to NATS which takes a list of servers.nc=awaitnats.connect(servers=servers)
awaitnc.publish("greet.joe", b"hello")
awaitnc.publish("greet.pam", b"hello")
awaitnc.publish("greet.bob", b"hello")
# await sub.unsubscribe()# await nc.drain()if__name__=="__main__":
asyncio.run(main())
subscriber.py
importosimportasyncioimportnatsfromnats.errorsimportTimeoutErrorservers=os.environ.get("NATS_URL", "nats://localhost:4222").split(",")
asyncdefmain():
# Create the connection to NATS which takes a list of servers.nc=awaitnats.connect(servers=servers)
# create a subscriptionsub=awaitnc.subscribe("greet.*")
try:
msg=awaitsub.next_msg(timeout=0.1)
print(msg)
exceptTimeoutError:
pass# print("timed out")if__name__=="__main__":
whileTrue:
asyncio.run(main())
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So I want a simple queueing service from NATS where my publisher can keep on putting messages in the queue and they persist unless they are acknowledged. I tried following the example on the following link and made 2 different files. One for subscriber and other for publisher but it doesn't work as expected. I only see one message instead of three.
publisher.py
subscriber.py
Am I doing something wrong? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions