r/FastAPI • u/Slampamper • Nov 19 '22
Question Fastapi with azure service bus
I'm looking to use a queuing service with FastAPI. I don't want to create two additional apps with celery and flower, but looking to integrate an azure service that could work as a queue, and am looking towards using azure service bus.
In order to use this I need to create a consumer that checks for new messages. Is it architecture wise OK to create a separate thread where this consumer lives? I have something simple working like this in my main file. I could also add this to a startup event
def receiving(Receiving = True):
while Receiving:
with ServiceBusClient.from_connection_string(connstr) as client:
with client.get_queue_receiver(queue_name, max_wait_time=30) as receiver:
for msg in receiver:
print(f"{datetime.now()}: {msg}")
receiver.complete_message(msg)t1 = Thread(target=receiving) t1.start()
Is this something that is desirable or would this lead to performance issues?
1
Upvotes
3
u/[deleted] Nov 19 '22
Not sure what service bus does or is. I'd probably go for whatever azures version of lambda functions is though.