Skip to content

Instantly share code, notes, and snippets.

@mrmamongo
Last active April 2, 2023 19:01
Show Gist options
  • Save mrmamongo/2fe750dc6d00597942405b9e9d25ad15 to your computer and use it in GitHub Desktop.
Save mrmamongo/2fe750dc6d00597942405b9e9d25ad15 to your computer and use it in GitHub Desktop.
import asyncio
import nats.errors
from nats import connect
from nats.aio.msg import Msg
PRIORITY = "high"
async def main():
nc = await connect()
js = nc.jetstream()
hp_sub = await js.subscribe(f"worker.task.{PRIORITY}.>")
default_sub = await js.subscribe(f"worker.task.>")
while True:
msg: Msg | None = None
try:
msg = await hp_sub.next_msg()
task_id = msg.subject
except nats.errors.TimeoutError:
try:
msg = await default_sub.next_msg()
except nats.errors.TimeoutError:
continue
# handle(msg)
if __name__ == '__main__':
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment