/// <summary> /// Adds return routing to message /// </summary> /// <param name="message">The message to add return routing</param> /// <param name="returnType">The message to add return routing</param> public static void AddReturnRouting(this AgentMessage message, ReturnRouteTypes returnType = ReturnRouteTypes.all) { message.AddDecorator(new TransportDecorator { ReturnRoute = returnType.ToString("G") }, DecoratorNames.TransportDecorator); }
/// <inheritdoc /> public async Task <MessageContext> SendReceiveAsync(IAgentContext agentContext, AgentMessage message, string recipientKey, string endpointUri, string[] routingKeys = null, string senderKey = null, ReturnRouteTypes returnType = ReturnRouteTypes.all) { Logger.LogInformation(LoggingEvents.SendMessage, "Recipient {0} Endpoint {1}", recipientKey, endpointUri); if (string.IsNullOrEmpty(message.Id)) { throw new AriesFrameworkException(ErrorCode.InvalidMessage, "@id field on message must be populated"); } if (string.IsNullOrEmpty(message.Type)) { throw new AriesFrameworkException(ErrorCode.InvalidMessage, "@type field on message must be populated"); } if (string.IsNullOrEmpty(endpointUri)) { throw new ArgumentNullException(nameof(endpointUri)); } var uri = new Uri(endpointUri); var dispatcher = GetDispatcher(uri.Scheme); if (dispatcher == null) { throw new AriesFrameworkException(ErrorCode.A2AMessageTransmissionError, $"No registered dispatcher for transport scheme : {uri.Scheme}"); } message.AddReturnRouting(returnType); var wireMsg = await CryptoUtils.PrepareAsync(agentContext, message, recipientKey, routingKeys, senderKey); var response = await dispatcher.DispatchAsync(uri, new PackedMessageContext(wireMsg)); if (response is PackedMessageContext responseContext) { return(await UnpackAsync(agentContext.Wallet, responseContext, senderKey)); } throw new InvalidOperationException("Invalid or empty response"); }