[Python] Consuming events from multiple Azure Event Hubs in one Python program

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have two event hubs, each with its own consumer group. I would like to receive events from each of them at the same time but I don't see anything related to this in the GitHub samples.

    More specifically, I would like to take advantage of asyncio for reading from the two topics concurrently but I'm new to asynchronous programming and I can't figure it out. I tried something like this but it never moves on to reading with client2:

    async with client1:
    async with client2:
    await client1.receive_batch(...)
    await client2.receive_batch(...)


    I also tried separating the async with statements and even tried adding await asyncio.sleep(1) in the on_event_batch function, just to make sure that control is given back to the event loop.

    At this point I'm not sure whether what I want to do simply cannot be achieved with asyncio or I just don't know how to use it.

    Any help will be appreciated, thanks!

    Continue reading...

Compartilhe esta Página