public Task Route(InboundBrokeredMessage inboundBrokeredMessage, TransactionContext transactionContext, ReplyToRoutingContext destinationRouterContext) { if (destinationRouterContext is null) { //TODO: log return(Task.CompletedTask); } try { var outbound = new OutboundBrokeredMessage(_messageIdGenerator?.GenerateId(inboundBrokeredMessage.Body).ToString(), inboundBrokeredMessage.Body, (IDictionary <string, object>)inboundBrokeredMessage.MessageContext, destinationRouterContext?.DestinationPath, inboundBrokeredMessage.BodyConverter); outbound.MessageContext[MessageContext.ReplyToGroupId] = destinationRouterContext.ReplyToGroupId; return(_router.Route(outbound, transactionContext)); } catch (Exception e) { throw new ReplyToRoutingExceptions(destinationRouterContext, e); } }
Task Dispatch <TMessage, TOptions>(IEnumerable <TMessage> messages, TransactionContext transactionContext, TOptions options, string destinationPath = null) where TMessage : IMessage where TOptions : RoutingOptions, new() { var outbounds = Dispatch(messages, destinationPath, options); options.MessageContext.TryGetValue(MessageContext.InfrastructureType, out var infraType); return(_messageRouter.Route(outbounds, transactionContext, (string)infraType)); }
/// <summary> /// Forwards an inbound brokered message to a destination /// </summary> /// <param name="inboundBrokeredMessage">The inbound brokered message to be forwarded to a receiver</param> /// <param name="forwardDestination">The destination path to forward the inbound brokered message to</param> /// <param name="transactionContext">The transactional information to use while routing</param> /// <returns>An awaitable <see cref="Task"/></returns> public Task Route(InboundBrokeredMessage inboundBrokeredMessage, string forwardDestination, TransactionContext transactionContext) { if (inboundBrokeredMessage is null) { throw new ArgumentNullException(nameof(inboundBrokeredMessage), $"An {typeof(InboundBrokeredMessage).Name} is required to be routed to the destination."); } if (string.IsNullOrWhiteSpace(forwardDestination)) { return(Task.CompletedTask); } var outboundMessage = OutboundBrokeredMessage.Forward(inboundBrokeredMessage, forwardDestination) .RefreshTimeToLive(); return(_router.Route(outboundMessage, transactionContext)); }
public Task Route(InboundBrokeredMessage inboundBrokeredMessage, TransactionContext transactionContext, ReplyToRoutingContext destinationRouterContext) { if (destinationRouterContext is null) { //TODO: log return(Task.CompletedTask); } try { var outbound = OutboundBrokeredMessage.Forward(inboundBrokeredMessage, destinationRouterContext?.DestinationPath); outbound.ApplicationProperties[ApplicationProperties.ReplyToGroupId] = destinationRouterContext.ReplyToGroupId; return(_router.Route(outbound, transactionContext)); } catch (Exception e) { throw new ReplyToRoutingExceptions(destinationRouterContext, e); } }
/// <summary> /// Forwards an inbound brokered message to a destination /// </summary> /// <param name="inboundBrokeredMessage">The inbound brokered message to be forwarded to a receiver</param> /// <param name="forwardDestination">The destination path to forward the inbound brokered message to</param> /// <param name="transactionContext">The transactional information to use while routing</param> /// <returns>An awaitable <see cref="Task"/></returns> public Task Route(InboundBrokeredMessage inboundBrokeredMessage, string forwardDestination, TransactionContext transactionContext) { if (inboundBrokeredMessage is null) { throw new ArgumentNullException(nameof(inboundBrokeredMessage), $"An {typeof(InboundBrokeredMessage).Name} is required to be routed to the destination."); } if (string.IsNullOrWhiteSpace(forwardDestination)) { return(Task.CompletedTask); } var outboundMessage = new OutboundBrokeredMessage(_messageIdGenerator?.GenerateId(inboundBrokeredMessage.Body).ToString(), inboundBrokeredMessage.Body, (IDictionary <string, object>)inboundBrokeredMessage.MessageContext, forwardDestination, inboundBrokeredMessage.BodyConverter); return(_router.Route(outboundMessage, transactionContext)); }
Task Dispatch <TMessage, TOptions>(TMessage message, string destinationPath, TransactionContext transactionContext, TOptions options) where TMessage : IMessage where TOptions : RoutingOptions, new() { if (options == null) { options = new TOptions(); } if (string.IsNullOrWhiteSpace(options.ContentType)) { throw new ArgumentNullException(nameof(options.ContentType), "Message content type is required"); } var converter = _bodyConverterFactory.CreateBodyConverter(options.ContentType); var outbound = new OutboundBrokeredMessage(options.MessageId, message, options.ApplicationProperties, destinationPath, converter); return(_messageRouter.Route(outbound, transactionContext)); }
/// <summary> /// Routes a brokered message to a brokered message receiver responsible for compensating a received message /// </summary> /// <param name="inboundBrokeredMessage">The inbound brokered message to be routed to the compensation destination</param> /// <param name="transactionContext">The transaction information that was received with <paramref name="inboundBrokeredMessage"/></param> /// <param name="destinationRouterContext">The <see cref="CompensationRoutingContext"/> containing contextual information describing the compensating action</param> /// <exception cref="CompensationRoutingException">An exception containing contextual information describing the failure during compensation and routing details</exception> /// <returns>An awaitable <see cref="Task"/></returns> public Task Route(InboundBrokeredMessage inboundBrokeredMessage, TransactionContext transactionContext, CompensationRoutingContext destinationRouterContext) { if (destinationRouterContext is null) { //TODO: log return(Task.CompletedTask); } try { if (destinationRouterContext is null) { throw new ArgumentNullException(nameof(destinationRouterContext), $"A '{typeof(CompensationRoutingContext).Name}' is required to route a compensation message"); } if (string.IsNullOrWhiteSpace(destinationRouterContext.CompensateDetails)) { throw new ArgumentNullException(nameof(destinationRouterContext.CompensateDetails), $"A compensation reason is required to route a compensation message"); } if (string.IsNullOrWhiteSpace(destinationRouterContext.CompensateDescription)) { throw new ArgumentNullException(nameof(destinationRouterContext.CompensateDescription), $"A compensation description is required to route a compensation message"); } var outbound = OutboundBrokeredMessage.Forward(inboundBrokeredMessage, destinationRouterContext.DestinationPath) .WithFailureDetails(destinationRouterContext.CompensateDetails) .WithFailureDescription(destinationRouterContext.CompensateDescription) .SetFailure(); return(_router.Route(outbound, transactionContext)); } catch (Exception causeOfRoutingFailure) { throw new CompensationRoutingException(destinationRouterContext, causeOfRoutingFailure); } }