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); } }
public static InboundBrokeredMessage WithRoutingSlip(this InboundBrokeredMessage message, RoutingSlip slip) { var serializedRoutingSlip = JsonConvert.SerializeObject(slip); message.MessageContextImpl[MessageContext.RoutingSlip] = serializedRoutingSlip; return(message); }
public static Task Forward(this IBrokeredMessageDispatcher dispatcher, InboundBrokeredMessage message, RoutingSlip slip, TransactionContext transactionContext) { var destination = slip.RouteToNextStep(); message.WithRoutingSlip(slip); return(dispatcher.Forward(message, destination, transactionContext)); }
///<inheritdoc/> public Task Route(InboundBrokeredMessage inboundBrokeredMessage, TransactionContext transactionContext, CompensationRoutingContext compensateContext) { if (!(compensateContext.Container.TryGet <Message>(out var receivedMessage))) { throw new InvalidOperationException($"The received {nameof(CompensationRoutingContext)} did not contain a {typeof(Message).Name}"); } if (!(transactionContext.Container.TryGet <MessageReceiver>(out var receiver))) { throw new InvalidOperationException($"The received {nameof(TransactionContext)} did not contain a {typeof(MessageReceiver).Name}"); } return(receiver.DeadLetterAsync(receivedMessage.SystemProperties.LockToken, (IDictionary <string, object>)inboundBrokeredMessage.ApplicationProperties)); }
/// <summary> /// Creates an object containing contextual information about an error that occurred while a message was being received /// </summary> /// <param name="failureDescription">The details of the error</param> /// <param name="failureDetail">The description of the error</param> public FailureContext(InboundBrokeredMessage inbound, string errorQueueName, string failureDescription, Exception failure, int deliveryCount, TransactionContext transactionContext) { if (string.IsNullOrWhiteSpace(failureDescription)) { throw new ArgumentException("A failure description is required when a failure occurs.", nameof(failureDescription)); } Inbound = inbound; ErrorQueueName = errorQueueName; FailureDescription = failureDescription; Failure = failure; DeliveryCount = deliveryCount; TransactionContext = transactionContext; }
/// <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)); }
/// <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); } }
public static OutboundBrokeredMessage Forward(InboundBrokeredMessage messageToForward, string forwardDestination) => new OutboundBrokeredMessage(Guid.NewGuid().ToString(), messageToForward.Body, (IDictionary <string, object>)messageToForward.ApplicationProperties, forwardDestination, messageToForward.BodyConverter);
public MessageBrokerContext(InboundBrokeredMessage brokeredMessage) { this.BrokeredMessage = brokeredMessage; }
public Task Forward(InboundBrokeredMessage inboundBrokeredMessage, string forwardDestination, TransactionContext transactionContext) => _forwarder.Route(inboundBrokeredMessage, forwardDestination, transactionContext);