feat/#61 - add one way communication option
Unit test coverage / pytest (push) Successful in 1m23s
/ build-and-push (push) Successful in 1m31s
Unit test coverage / pytest (pull_request) Successful in 1m8s

This commit is contained in:
Stanislav Hejny
2025-07-23 18:33:34 +01:00
parent 3ee62b0437
commit b41ca04801
+38 -1
View File
@@ -297,7 +297,7 @@ class DataMessageHandler:
future = asyncio.Future() future = asyncio.Future()
# Store the future in the outstanding dictionary using the message ID as the key # Store the future in the outstanding dictionary using the message ID as the key
message_id = message.id() message_id = message.id().as_string()
self.outstanding[message_id] = future self.outstanding[message_id] = future
# Create a Pika message with the correlation ID set to the message ID # Create a Pika message with the correlation ID set to the message ID
@@ -328,3 +328,40 @@ class DataMessageHandler:
) )
return future return future
async def send_command(self, route, message: DataMessage) -> bool:
"""
Sends an RPC message to the specified route and returns a Future that will be completed
when the response is received.
:param route: AMQRoute object containing exchange and routing information
:param message: DataMessage to be sent
:return: Future that will be completed with the response payload
"""
# Create a Pika message with the correlation ID set to the message ID
pika_message = Message(
body=DataMessageFactory.serialize(message),
correlation_id=message.id().as_string(),
content_type=(
message.content_type()[0]
if isinstance(message.content_type(), list)
else message.content_type()
),
)
# Get the exchange from the route
rpc_exchange_name = route.exchange
exchange: AbstractRobustExchange = await self.rabbit_mq_client.channel.declare_exchange(
name=rpc_exchange_name, type=ExchangeType.topic
)
# Publish the message to the exchange with the component name as the routing key
await exchange.publish(message=pika_message, routing_key=route.component_name)
logging_debug(
"###### RPC Request Published to exchg:(%s) routing_key=%s, msgId=%s",
rpc_exchange_name,
route.component_name,
message.id().as_string(),
)
return True