'aio pika Consumer 0: Queue empty. Stopping

How do I run the publisher function inside the consumer function? it gives me aio_pika.exceptions.QueueEmpty error from here

async def consume(consumer_id) -> None: async with channel_pool.acquire() as channel: # type: aio_pika.Channel

        queue = await channel.declare_queue(
            queue_name, durable=False, auto_delete=False,
        )
           
    while True :
        try:
            m = await queue.get(timeout=300 * 10)
            message = m.body.decode('utf-8')
         

            try :
                j = json.loads(message)
                print(j)
            except Exception as e:
                print("error" % (e,))
                raise e
            m.ack()
            

    
        except aio_pika.exceptions.QueueEmpty:
            
            print("Consumer %s: Queue empty. Stopping." % consumer_id)
            break
        
     

           
       
       
       
     
async def publish(data) -> None:
    async with channel_pool.acquire() as channel:  
   
        await channel.default_exchange.publish(
            aio_pika.Message(
                body=json.dumps(data).encode(),
               
            ),
         
            queue_name,
        )




async with connection_pool, channel_pool:
    consumer_pool = []
    print("consumer started")
    for i in range(1):
        consumer_pool.append(consume(consumer_id=i))

    await asyncio.gather(*consumer_pool)

if name == "main": asyncio.run(main())

I want to create 2 queues and send that data to a single consumers how can i solve



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source