public async Task Invoke(IIncomingPhysicalMessageContext context, Func <IIncomingPhysicalMessageContext, Task> next) { await next(context).ConfigureAwait(false); var subscriptionMessageType = GetSubscriptionMessageTypeFrom(context.Message); if (subscriptionMessageType != null) { string returnAddress; if (!context.Message.Headers.TryGetValue(Headers.SubscriberTransportAddress, out returnAddress)) { context.Message.Headers.TryGetValue(Headers.ReplyToAddress, out returnAddress); } var intent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), context.Message.Headers[Headers.MessageIntent], true); if (intent != intentToHandle) { return; } action(new SubscriptionEventArgs { MessageType = subscriptionMessageType, SubscriberReturnAddress = returnAddress }, scenarioContext); } }
protected override async Task Terminate(IIncomingPhysicalMessageContext context) { var message = context.Message; var timeoutId = message.Headers["Timeout.Id"]; var timeoutData = await persister.Peek(timeoutId, context.Extensions).ConfigureAwait(false); if (timeoutData == null) { return; } var sendOptions = new DispatchOptions(new UnicastAddressTag(timeoutData.Destination), dispatchConsistency); timeoutData.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); timeoutData.Headers["NServiceBus.RelatedToTimeoutId"] = timeoutData.Id; await dispatcher.Dispatch(new[] { new TransportOperation(new OutgoingMessage(message.MessageId, timeoutData.Headers, timeoutData.State), sendOptions) }, context.Extensions).ConfigureAwait(false); var timeoutRemoved = await persister.TryRemove(timeoutId, context.Extensions).ConfigureAwait(false); if (!timeoutRemoved) { // timeout was concurrently removed between Peek and TryRemove. Throw an exception to rollback the dispatched message if possible. throw new Exception($"timeout '{timeoutId}' was concurrently processed."); } }
public static IRoutingContext CreateRoutingContext(this IIncomingPhysicalMessageContext context, IReadOnlyCollection <RoutingStrategy> routingStrategies) { return(new ForwardingRoutingContext( new OutgoingMessage(context.MessageId, context.Message.Headers, context.Message.Body), routingStrategies, context )); }
public IDisposable SetCurrentPipelineContext(IIncomingPhysicalMessageContext context) { if (pipelineContext.Value != null) { throw new InvalidOperationException("Attempt to overwrite an existing pipeline context in BusSession.Current."); } pipelineContext.Value = new PipelineContextSession(context); return(new ContextSCope(this)); }
bool Authorizer(IIncomingPhysicalMessageContext context) { var isFromSubscriber1 = context .MessageHeaders["NServiceBus.SubscriberEndpoint"] .EndsWith("Subscriber1"); if (!isFromSubscriber1) { var testContext = (TestContext)ScenarioContext; testContext.DeclinedSubscriber2 = true; } return(isFromSubscriber1); }
bool Authorizer(IIncomingPhysicalMessageContext context) { var isUnsubscribe = context .MessageHeaders["NServiceBus.MessageIntent"] == "Unsubscribe"; if (!isUnsubscribe) { return(true); } var testContext = (TestContext)ScenarioContext; testContext.DeclinedUnSubscribe = true; return(false); }
public void Enrich(Activity activity, IIncomingPhysicalMessageContext context) { var destinationName = _settings.LogicalAddress(); const string operationName = "process"; activity.DisplayName = $"{destinationName} {operationName}"; activity.AddTag("messaging.message_id", context.Message.MessageId); activity.AddTag("messaging.operation", operationName); activity.AddTag("messaging.destination", destinationName); activity.AddTag("messaging.message_payload_size_bytes", context.Message.Body.Length.ToString()); Enrich(activity, context.MessageHeaders); if (activity.IsAllDataRequested && _options.CaptureMessageBody) { activity.AddTag("messaging.message_payload", Encoding.UTF8.GetString(context.Message.Body)); } }
/// <summary> /// Creates a <see cref="IForwardingContext" /> based on the current context. /// </summary> public static IForwardingContext CreateForwardingContext(this ForkConnector <IIncomingPhysicalMessageContext, IForwardingContext> forwardingContext, OutgoingMessage message, string forwardingAddress, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(message), message); Guard.AgainstNullAndEmpty(nameof(forwardingAddress), forwardingAddress); Guard.AgainstNull(nameof(sourceContext), sourceContext); var connector = (IForkConnector <IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IForwardingContext>)forwardingContext; return(connector.CreateForwardingContext(message, forwardingAddress, sourceContext)); }
/// <summary> /// Creates a <see cref="IAuditContext" /> based on the current context. /// </summary> public static IAuditContext CreateAuditContext(this ForkConnector<IIncomingPhysicalMessageContext, IAuditContext> forkConnector, OutgoingMessage message, string auditAddress, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(sourceContext), sourceContext); var connector = (IForkConnector<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IAuditContext>) forkConnector; return connector.CreateAuditContext(message, auditAddress, sourceContext); }
internal static IAuditContext CreateAuditContext(this IForkConnector<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IAuditContext> forkConnector, OutgoingMessage message, string auditAddress, IIncomingPhysicalMessageContext sourceContext) { return new AuditContext(message, auditAddress, sourceContext); }
/// <summary> /// Creates a <see cref="IIncomingLogicalMessageContext" /> based on the current context. /// </summary> public static IIncomingLogicalMessageContext CreateIncomingLogicalMessageContext(this StageConnector <IIncomingPhysicalMessageContext, IIncomingLogicalMessageContext> stageConnector, LogicalMessage logicalMessage, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(logicalMessage), logicalMessage); Guard.AgainstNull(nameof(sourceContext), sourceContext); return(new IncomingLogicalMessageContext(logicalMessage, sourceContext)); }
internal static IAuditContext CreateAuditContext(this IForkConnector <IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IAuditContext> forkConnector, OutgoingMessage message, string auditAddress, IIncomingPhysicalMessageContext sourceContext) { _ = forkConnector; return(new AuditContext(message, auditAddress, sourceContext)); }
/// <summary> /// Creates a <see cref="IAuditContext" /> based on the current context. /// </summary> public static IAuditContext CreateAuditContext(this ForkConnector <IIncomingPhysicalMessageContext, IAuditContext> forkConnector, OutgoingMessage message, string auditAddress, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(sourceContext), sourceContext); var connector = (IForkConnector <IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IAuditContext>)forkConnector; return(connector.CreateAuditContext(message, auditAddress, sourceContext)); }
internal static IBatchDispatchContext CreateBatchDispatchContext(this IStageForkConnector <ITransportReceiveContext, IIncomingPhysicalMessageContext, IBatchDispatchContext> stageForkConnector, IReadOnlyCollection <TransportOperation> transportOperations, IIncomingPhysicalMessageContext sourceContext) { _ = stageForkConnector; return(new BatchDispatchContext(transportOperations, sourceContext)); }
internal static IBatchDispatchContext CreateBatchDispatchContext(this IStageForkConnector<ITransportReceiveContext, IIncomingPhysicalMessageContext, IBatchDispatchContext> stageForkConnector, IReadOnlyCollection<TransportOperation> transportOperations, IIncomingPhysicalMessageContext sourceContext) { return new BatchDispatchContext(transportOperations, sourceContext); }
public static IForwardingContext CreateForwardingContext(this ForkConnector <IIncomingPhysicalMessageContext, IForwardingContext> forwardingContext, OutgoingMessage message, string forwardingAddress, IIncomingPhysicalMessageContext sourceContext) { throw new NotImplementedException(); }
internal IncomingLogicalMessageContext(LogicalMessage logicalMessage, IIncomingPhysicalMessageContext parentContext) : this(logicalMessage, parentContext.MessageId, parentContext.ReplyToAddress, parentContext.Message.Headers, parentContext) { }
internal IncomingLogicalMessageContext(LogicalMessage logicalMessage, IIncomingPhysicalMessageContext parentContext) : this(logicalMessage, parentContext.MessageId, parentContext.ReplyToAddress, parentContext.Message.Headers, parentContext) { }
/// <summary> /// Creates a <see cref="IForwardingContext" /> based on the current context. /// </summary> public static IForwardingContext CreateForwardingContext(this ForkConnector<IIncomingPhysicalMessageContext, IForwardingContext> forwardingContext, OutgoingMessage message, string forwardingAddress, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(message), message); Guard.AgainstNullAndEmpty(nameof(forwardingAddress), forwardingAddress); Guard.AgainstNull(nameof(sourceContext), sourceContext); var connector = (IForkConnector<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IForwardingContext>) forwardingContext; return connector.CreateForwardingContext(message, forwardingAddress, sourceContext); }
/// <summary> /// Creates a <see cref="IIncomingLogicalMessageContext" /> based on the current context. /// </summary> public static IIncomingLogicalMessageContext CreateIncomingLogicalMessageContext(this StageConnector<IIncomingPhysicalMessageContext, IIncomingLogicalMessageContext> stageConnector, LogicalMessage logicalMessage, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(logicalMessage), logicalMessage); Guard.AgainstNull(nameof(sourceContext), sourceContext); return new IncomingLogicalMessageContext(logicalMessage, sourceContext); }
internal static IForwardingContext CreateForwardingContext(this IForkConnector<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IForwardingContext> forwardingContext, OutgoingMessage message, string forwardingAddress, IIncomingPhysicalMessageContext sourceContext) { return new ForwardingContext(message, forwardingAddress, sourceContext); }
internal static IForwardingContext CreateForwardingContext(this IForkConnector <IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext, IForwardingContext> forwardingContext, OutgoingMessage message, string forwardingAddress, IIncomingPhysicalMessageContext sourceContext) { return(new ForwardingContext(message, forwardingAddress, sourceContext)); }
public void Enrich(Activity activity, IIncomingPhysicalMessageContext context) { }
public static void AddAuditContext(this IIncomingPhysicalMessageContext context) { var auditFilterContext = new AuditFilterContext(); context.Extensions.Set(auditFilterContext); }
/// <summary> /// Creates a <see cref="IBatchDispatchContext" /> based on the current context. /// </summary> public static IBatchDispatchContext CreateBatchDispatchContext(this StageForkConnector <ITransportReceiveContext, IIncomingPhysicalMessageContext, IBatchDispatchContext> stageForkConnector, IReadOnlyCollection <TransportOperation> transportOperations, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(transportOperations), transportOperations); Guard.AgainstNull(nameof(sourceContext), sourceContext); return(new BatchDispatchContext(transportOperations, sourceContext)); }
protected override async Task Terminate(IIncomingPhysicalMessageContext context) { var message = context.Message; var sagaId = Guid.Empty; string sagaIdString; if (message.Headers.TryGetValue(Headers.SagaId, out sagaIdString)) { sagaId = Guid.Parse(sagaIdString); } if (message.Headers.ContainsKey(TimeoutManagerHeaders.ClearTimeouts)) { if (sagaId == Guid.Empty) { throw new InvalidOperationException("Invalid saga id specified, clear timeouts is only supported for saga instances"); } await persister.RemoveTimeoutBy(sagaId, context.Extensions).ConfigureAwait(false); } else { string expire; if (!message.Headers.TryGetValue(TimeoutManagerHeaders.Expire, out expire)) { throw new InvalidOperationException("Non timeout message arrived at the timeout manager, id:" + message.MessageId); } var destination = message.GetReplyToAddress(); string routeExpiredTimeoutTo; if (message.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo)) { destination = routeExpiredTimeoutTo; } var data = new TimeoutData { Destination = destination, SagaId = sagaId, State = message.Body, Time = DateTimeExtensions.ToUtcDateTime(expire), Headers = message.Headers, OwningTimeoutManager = owningTimeoutManager }; if (data.Time.AddSeconds(-1) <= DateTime.UtcNow) { var sendOptions = new DispatchOptions(new UnicastAddressTag(data.Destination), DispatchConsistency.Default); var outgoingMessage = new OutgoingMessage(message.MessageId, data.Headers, data.State); await dispatcher.Dispatch(new[] { new TransportOperation(outgoingMessage, sendOptions) }, context.Extensions).ConfigureAwait(false); return; } await persister.Add(data, context.Extensions).ConfigureAwait(false); poller.NewTimeoutRegistered(data.Time); } }
/// <summary> /// Creates a <see cref="IBatchDispatchContext" /> based on the current context. /// </summary> public static IBatchDispatchContext CreateBatchDispatchContext(this StageForkConnector<ITransportReceiveContext, IIncomingPhysicalMessageContext, IBatchDispatchContext> stageForkConnector, IReadOnlyCollection<TransportOperation> transportOperations, IIncomingPhysicalMessageContext sourceContext) { Guard.AgainstNull(nameof(transportOperations), transportOperations); Guard.AgainstNull(nameof(sourceContext), sourceContext); return new BatchDispatchContext(transportOperations, sourceContext); }