#15 - Implement Backpressure UPDATE & IDLE, setup AMQ handler in its own thread

This commit is contained in:
Stanislav Hejny
2025-04-28 00:49:35 +01:00
parent 88d45a9b67
commit 3dfb7a821d
10 changed files with 213 additions and 77 deletions
+5 -6
View File
@@ -27,6 +27,7 @@ from amqp.adapter.logging_utils import logging_error, logging_debug, logging_inf
from amqp.config.amq_configuration import AMQConfiguration
from amqp.model.model import DataMessage, DataResponse
from amqp.router.router_base import AMQ_REPLY_TO_EXCHANGE
from amqp.router.utils import await_result
@dataclass
@@ -86,12 +87,10 @@ async def _convert_file_response(
# All calls to RabbitMQ API have to be called threadsafe, because those appear to be attached to parent
# event loop, and need to execute at that event loop, not the current one
_future = asyncio.run_coroutine_threadsafe(_wrap_amq_api_calls(connection), loop)
while not _future.done():
await asyncio.sleep(
0.1
) # allow coroutine to execute. calling _future.result() will block the entire thread and the coroutine will never execute
_channel, _exchange, _routing_key = _future.result()
# allow coroutine to execute. calling _future.result() will block the entire thread and the coroutine will never execute
_channel, _exchange, _routing_key = await await_result(
asyncio.run_coroutine_threadsafe(_wrap_amq_api_calls(connection), loop)
)
# publish_file also needs RabbitMQ API, ensure the loop is passed as argument
(_stream_name, _file_size) = await file_handler.publish_file(
_exchange, obj.path, _routing_key, loop