With the following I am trying to connect to my Rabbit instance using the pika AsyncioConnection adapter
import asyncio
import pika
from pika.adapters.asyncio_connection import AsyncioConnection
async def start_consuming():
channel = AsyncioConnection(
parameters=pika.URLParameters(AMQP_URL),
)
channel.ioloop.run_forever()
async def main():
await asyncio.gather(start_consuming())
if __name__ == '__main__':
asyncio.run(main())
Once the code hits the line when channel.ioloop.run_forever()
is invoked it prints this error:
File "/Users/asant/.pyenv/versions/3.12.2/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/asant/.pyenv/versions/3.12.2/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/asant/.pyenv/versions/3.12.2/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/asant/Desktop/enrichment-consumer/app/app.py", line 31, in main
await asyncio.gather(start_consuming())
File "/Users/asant/Desktop/enrichment-consumer/app/app.py", line 27, in start_consuming
channel.ioloop.run_forever()
File "/Users/asant/.pyenv/versions/3.12.2/lib/python3.12/asyncio/base_events.py", line 628, in run_forever
self._check_running()
File "/Users/asant/.pyenv/versions/3.12.2/lib/python3.12/asyncio/base_events.py", line 620, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running