private void Initiate(IActivityFactory activityFactory, IBaseMessage message, string processName) { var previousTrackingContext = message.GetTrackingContext(); // an outbound message without an ongoing process --i.e. that has no process affiliation-- denotes a // publish/subscribe, or messaging-only process and the whole process needs to be tracked; that means the // initiating messaging step, whose MessagingStepActivityId is still conveyed by the ambient // previousTrackingContext, as well as the currently ongoing messaging step, which completes the process. var isMessagingProcess = message.Direction().IsOutbound() && !previousTrackingContext.HasProcessAffiliation() && !previousTrackingContext.MessagingStepActivityId.IsNullOrEmpty(); if (_logger.IsDebugEnabled) { _logger.Debug($"Initiating tracking of a messaging {(isMessagingProcess ? "process" : "step")}."); } _process = isMessagingProcess ? activityFactory.CreateProcess(message, processName) : previousTrackingContext.HasProcessAffiliation() ? activityFactory.FindProcess(previousTrackingContext) : null; _previousMessagingStep = isMessagingProcess ? activityFactory.FindMessagingStep(previousTrackingContext) : null; _messagingStep = activityFactory.CreateMessagingStep(message); }
public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message) { if (message.Direction().IsInbound()) { var correlationId = message.GetProperty(SBMessagingProperties.CorrelationId); if (!correlationId.IsNullOrEmpty()) { message.PromoteCorrelationToken(correlationId); } var messageType = message.GetProperty(BrokeredProperties.MessageType); if (!messageType.IsNullOrEmpty()) { message.Promote(BtsProperties.MessageType, messageType); } } else { var correlationToken = message.GetProperty(BizTalkFactoryProperties.CorrelationToken); if (!correlationToken.IsNullOrEmpty()) { message.SetProperty(SBMessagingProperties.CorrelationId, correlationToken); } var messageType = message.GetOrProbeMessageType(pipelineContext); if (!messageType.IsNullOrEmpty()) { message.SetProperty(BrokeredProperties.MessageType, messageType); } } return(message); }
private static bool IsSolicitResponse(this IBaseMessage message) { if (message.GetProperty(BtsProperties.IsSolicitResponse) ?? false) { return(true); } return(message.Direction().IsInbound() && (message.GetProperty(BtsProperties.WasSolicitResponse) ?? false)); }
public static PortType PortType(this IBaseMessage message) { if (message.IsSolicitResponse()) { return(Message.PortType.SolicitResponseSendPort); } if (message.IsRequestResponse()) { return(Message.PortType.RequestResponseReceivePort); } if (message.Direction().IsInbound()) { return(Message.PortType.OneWayReceivePort); } if (message.Direction().IsOutbound()) { return(Message.PortType.OneWaySendPort); } throw new Exception("Unable to determine port type."); }
public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message) { var customBrokeredMessagePropertyNamespace = message.GetProperty(SBMessagingProperties.CustomBrokeredMessagePropertyNamespace) ?? throw new InvalidOperationException($"{nameof(CustomBrokeredMessagePropertyNamespace)} has no value defined in SB-Messaging adapter configuration."); if (message.Direction().IsInbound()) { var correlationId = message.GetProperty(SBMessagingProperties.CorrelationId); // use the native BTS API instead of the message.PromoteCorrelationId(correlationId) to have no dependency on // BizTalk.Schemas which would reversed the desired dependency order, i.e. from an artifact component // (BizTalk.Schemas) to a runtime one (BizTalk.Pipeline.MicroComponents itself) if (!correlationId.IsNullOrEmpty()) { message.Context.Promote(nameof(SBMessagingProperties.CorrelationId), PropertySchemaNamespaces.BizTalkFactory, correlationId); } var messageType = (string)message.Context.Read(nameof(BizTalkFactoryProperties.MessageType), customBrokeredMessagePropertyNamespace); if (!messageType.IsNullOrEmpty()) { message.Promote(BtsProperties.MessageType, messageType); } } else { // use the native BTS API instead of the message.GetProperty(BizTalkFactoryProperties.CorrelationId) to have no // dependency on BizTalk.Schemas which would reversed the desired dependency order, i.e. from an artifact component // (BizTalk.Schemas) to a runtime one (BizTalk.Pipeline.MicroComponents itself) var correlationId = (string)message.Context.Read(nameof(SBMessagingProperties.CorrelationId), BizTalkFactoryProperties.MessageType.Namespace); if (!correlationId.IsNullOrEmpty()) { message.SetProperty(SBMessagingProperties.CorrelationId, correlationId); } var messageType = message.GetOrProbeMessageType(pipelineContext); if (!messageType.IsNullOrEmpty()) { message.Context.Write(nameof(BizTalkFactoryProperties.MessageType), customBrokeredMessagePropertyNamespace, messageType); } } return(message); }
public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage message) { if (TrackingModes != ActivityTrackingModes.None) { var messageDirection = message.Direction(); var isSolicitResponse = message.PortType().IsSolicitResponse(); // tracking context can only be restored for the inbound message of a Solicit-Response MEP, i.e. when BizTalk was // the initiator of the 2-way MEP if (messageDirection.IsInbound() && isSolicitResponse) { RestoreCachedTrackingContext(message); } var context = new Context(pipelineContext, message, TrackingModes); var activityTracker = Activity.Tracking.Messaging.ActivityTracker.Create(context); var messageBodyTracker = MessageBodyTracker.Create(context); // try to replace a claim token message with its original body's payload stream messageBodyTracker.TryCheckOutMessageBody(); // ensure a TrackingStream has been setup and ascertain TrackingModes messageBodyTracker.SetupTracking(); // perform the necessary setup to ensure TrackingContext is initiated early but information is collected at // stream's end activityTracker.TrackActivity(); // try to replace message body's original payload with a claim token, this will drain the stream and, hence, ensure // activity tracking is completed messageBodyTracker.TryCheckInMessageBody(); // tracking context can only be cached for the outbound message of a Solicit-Response MEP, i.e. when BizTalk is the // initiator of the 2-way MEP if (messageDirection.IsOutbound() && isSolicitResponse) { CacheTrackingContext(message, message.ResolveTrackingContextCacheDuration(TrackingContextCacheDuration)); } } return(message); }
public static bool IsInitiatingMessageExchangePattern(this IBaseMessage message) { return((message.PortType().IsRequestResponse() && message.Direction().IsInbound()) || (message.PortType().IsSolicitResponse() && message.Direction().IsOutbound()) || message.PortType().IsOneWay()); }