feat/#63 - cleverswarm unidirectional command
Unit test coverage / pytest (push) Has been cancelled
/ build-and-push (push) Has been cancelled
Unit test coverage / pytest (pull_request) Failing after 1m51s

This commit is contained in:
Stanislav Hejny
2025-07-26 15:29:07 +01:00
parent 9491517696
commit 41fbe46129
12 changed files with 148 additions and 86 deletions
+20 -13
View File
@@ -256,7 +256,7 @@ class DataMessageHandler:
try:
_a_message = AMQMessage(amq_message, self.rabbit_mq_client.connection)
_response: DataResponse = await self.service_adapter.on_rpc(_a_message)
_response: DataResponse = await self.on_rpc(_a_message)
logging_debug(f"Result in thread: {_response}")
try:
await self.send_reply(message.reply_to, _response)
@@ -301,10 +301,10 @@ class DataMessageHandler:
AttributeError: If the specified class or function/method does not exist.
Exception: For any other errors during invocation.
"""
package_name: str = a_message.domain()
class_name: str = a_message.path()
function_name: str = a_message.method()
kwargs: Dict[str, Any] = parse_map_string(a_message.body().decode("utf-8"))
package_name: str = a_message.method()
class_name: str = a_message.domain()
function_name: str = a_message.path()
kwargs: Dict[str, Any] = parse_map_string(a_message._base64body.decode("utf-8"))
return await invoke_command(
package_name, class_name, function_name, a_message.id().as_string(), kwargs
@@ -490,16 +490,23 @@ class DataMessageHandler:
:param message: DataMessage to be sent
:return: Future that will be completed with the response payload
"""
rmq_body = DataMessageFactory.serialize(message)
cid = message.id().as_string()
ctype = (
message.content_type()[0]
if isinstance(message.content_type(), list)
else message.content_type()
)
print(
f"Sending RPC command to route: {route}, message ID: {cid} with body: {rmq_body} correlation ID: {cid}, content type: {ctype}"
)
# 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()
),
body=rmq_body,
correlation_id=cid,
content_type=ctype,
)
print(f"SENDING RPC COMMAND: {pika_message.body} with ID: {message.id().as_string()}")
# Get the exchange from the route
rpc_exchange_name = route.exchange
@@ -509,7 +516,7 @@ class DataMessageHandler:
# 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(
logging_info(
"###### RPC Request Published to exchg:(%s) routing_key=%s, msgId=%s",
rpc_exchange_name,
route.component_name,
+3 -3
View File
@@ -151,13 +151,13 @@ class AMQService:
"""
route: Optional[AMQRoute] = self.router.find_route_by_service(service_name)
if route is not None:
message: DataMessage = self.data_message_factory.create_rpc_message(
m: DataMessage = self.data_message_factory.create_rpc_message(
fq_method_name=fq_method_name,
swarm_id=self.amq_configuration.amq_adapter.swarm_task_id,
**kwargs,
args=kwargs,
)
asyncio.run_coroutine_threadsafe(
self.amq_data_message_handler.send_command(route, message),
self.amq_data_message_handler.send_command(route, m),
loop=self.backpressure_handler.loop,
)
return True