Last active
April 2, 2023 19:01
-
-
Save mrmamongo/2fe750dc6d00597942405b9e9d25ad15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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