예제 #1
0
        static Task SendMessage(this IBehaviorContext context, Type messageType, object message, SendOptions options)
        {
            var cache    = context.Extensions.Get <IPipelineCache>();
            var pipeline = cache.Pipeline <IOutgoingSendContext>();

            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var outgoingContext = new OutgoingSendContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            if (options.DelayedDeliveryConstraint != null)
            {
                // we can't add the constraints directly to the SendOptions ContextBag as the options can be reused
                // and the delivery constraints might be removed by the TimeoutManager logic.
                outgoingContext.AddDeliveryConstraint(options.DelayedDeliveryConstraint);
            }

            return(pipeline.Invoke(outgoingContext));
        }
        static void SetConversationIdHeader(IOutgoingPhysicalMessageContext context, IncomingMessage incomingMessage)
        {
            string conversationIdFromCurrentMessageContext;
            string userDefinedConversationId;
            var    hasUserDefinedConversationId = context.Headers.TryGetValue(Headers.ConversationId, out userDefinedConversationId);

            if (incomingMessage != null && incomingMessage.Headers.TryGetValue(Headers.ConversationId, out conversationIdFromCurrentMessageContext))
            {
                if (hasUserDefinedConversationId)
                {
                    throw new Exception($"Cannot set the {Headers.ConversationId} header to '{userDefinedConversationId}' as it cannot override the incoming header value ('{conversationIdFromCurrentMessageContext}').");
                }

                context.Headers[Headers.ConversationId] = conversationIdFromCurrentMessageContext;
                return;
            }

            if (hasUserDefinedConversationId)
            {
                // do not override user defined conversation id if no incoming message exists.
                return;
            }

            context.Headers[Headers.ConversationId] = CombGuid.Generate().ToString();
        }
예제 #3
0
        IContainSagaData CreateNewSagaEntity(SagaMetadata metadata, IInvokeHandlerContext context)
        {
            var sagaEntityType = metadata.SagaEntityType;

            var sagaEntity = (IContainSagaData)Activator.CreateInstance(sagaEntityType);

            sagaEntity.Id = CombGuid.Generate();
            sagaEntity.OriginalMessageId = context.MessageId;

            string replyToAddress;

            if (context.Headers.TryGetValue(Headers.ReplyToAddress, out replyToAddress))
            {
                sagaEntity.Originator = replyToAddress;
            }

            var lookupValues = context.Extensions.GetOrCreate <SagaLookupValues>();

            SagaLookupValues.LookupValue value;
            if (lookupValues.TryGet(sagaEntityType, out value))
            {
                var propertyInfo = sagaEntityType.GetProperty(value.PropertyName);

                var convertedValue = TypeDescriptor.GetConverter(propertyInfo.PropertyType)
                                     .ConvertFromInvariantString(value.PropertyValue.ToString());

                propertyInfo.SetValue(sagaEntity, convertedValue);
            }

            return(sagaEntity);
        }
예제 #4
0
        IContainSagaData CreateNewSagaEntity(Type sagaType)
        {
            var sagaEntityType = SagaConfigurationCache.GetSagaEntityTypeForSagaType(sagaType);

            if (sagaEntityType == null)
            {
                throw new InvalidOperationException("No saga entity type could be found for saga: " + sagaType);
            }

            var sagaEntity = (IContainSagaData)Activator.CreateInstance(sagaEntityType);

            sagaEntity.Id = CombGuid.Generate();

            TransportMessage physicalMessage;

            if (currentContext.TryGet(IncomingContext.IncomingPhysicalMessageKey, out physicalMessage))
            {
                sagaEntity.OriginalMessageId = physicalMessage.Id;

                if (physicalMessage.ReplyToAddress != null)
                {
                    sagaEntity.Originator = physicalMessage.ReplyToAddress.ToString();
                }
            }

            return(sagaEntity);
        }
예제 #5
0
 /// <summary>
 ///     Initializes the transport message with a CombGuid as identifier
 /// </summary>
 public TransportMessage()
 {
     id = CombGuid.Generate().ToString();
     Headers[NServiceBus.Headers.MessageId] = id;
     CorrelationId = id;
     MessageIntent = MessageIntentEnum.Send;
     Headers[NServiceBus.Headers.NServiceBusVersion] = GitFlowVersion.MajorMinorPatch;
     Headers[NServiceBus.Headers.TimeSent]           = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);
 }
예제 #6
0
 /// <summary>
 /// Initializes the transport message with a CombGuid as identifier
 /// </summary>
 public TransportMessage()
 {
     id = CombGuid.Generate().ToString();
     Headers[NServiceBus.Headers.MessageId] = id;
     CorrelationId = id;
     Headers.Add(NServiceBus.Headers.OriginatingEndpoint, Configure.EndpointName);
     Headers.Add(NServiceBus.Headers.OriginatingMachine, RuntimeEnvironment.MachineName);
     MessageIntent = MessageIntentEnum.Send;
 }
예제 #7
0
        /// <summary>
        ///     Initializes the transport message with a CombGuid as identifier
        /// </summary>
        public TransportMessage()
        {
            id = CombGuid.Generate().ToString();
            Headers[NServiceBus.Headers.MessageId] = id;
            CorrelationId = id;
            Headers.Add(NServiceBus.Headers.OriginatingEndpoint, Configure.EndpointName);
            Headers.Add(NServiceBus.Headers.OriginatingHostId, UnicastBus.HostIdForTransportMessageBecauseEverythingIsStaticsInTheConstructor.ToString("N"));
            MessageIntent = MessageIntentEnum.Send;
            Headers[NServiceBus.Headers.NServiceBusVersion] = GitFlowVersion.MajorMinorPatch;
            Headers[NServiceBus.Headers.TimeSent]           = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow);

            AddBackwardsCompatibilityHeaders();
        }
예제 #8
0
        static Task Publish(IBehaviorContext context, Type messageType, object message, PublishOptions options)
        {
            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var publishContext = new OutgoingPublishContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            return(publishContext.InvokePipeline <IOutgoingPublishContext>());
        }
예제 #9
0
        Task ReplyMessage(IBehaviorContext context, Type messageType, object message, ReplyOptions options)
        {
            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var outgoingContext = new OutgoingReplyContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            return(replyPipeline.Invoke(outgoingContext));
        }
        IContainSagaData CreateNewSagaEntity(SagaMetadata metadata, LogicalMessage message)
        {
            var sagaEntityType = metadata.SagaEntityType;

            var sagaEntity = (IContainSagaData)Activator.CreateInstance(sagaEntityType);

            sagaEntity.Id = CombGuid.Generate();
            sagaEntity.OriginalMessageId = message.Headers[Headers.MessageId];

            string replyToAddress;

            if (message.Headers.TryGetValue(Headers.ReplyToAddress, out replyToAddress))
            {
                sagaEntity.Originator = replyToAddress;
            }

            return(sagaEntity);
        }
        static void ApplyHeaders(IOutgoingPhysicalMessageContext context)
        {
            var conversationId = CombGuid.Generate().ToString();

            IncomingMessage incomingMessage;

            if (context.TryGetIncomingPhysicalMessage(out incomingMessage))
            {
                context.Headers[Headers.RelatedTo] = incomingMessage.MessageId;

                string conversationIdFromCurrentMessageContext;
                if (incomingMessage.Headers.TryGetValue(Headers.ConversationId, out conversationIdFromCurrentMessageContext))
                {
                    conversationId = conversationIdFromCurrentMessageContext;
                }
            }

            context.Headers[Headers.ConversationId] = conversationId;
        }
예제 #12
0
        Task SendMessage(IBehaviorContext context, Type messageType, object message, SendOptions options)
        {
            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var outgoingContext = new OutgoingSendContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            MergeDispatchProperties(outgoingContext, options.DispatchProperties);

            return(sendPipeline.Invoke(outgoingContext));
        }
예제 #13
0
        static Task ReplyMessage(this IBehaviorContext context, Type messageType, object message, ReplyOptions options)
        {
            var cache    = context.Extensions.Get <IPipelineCache>();
            var pipeline = cache.Pipeline <IOutgoingReplyContext>();

            var messageId = options.UserDefinedMessageId ?? CombGuid.Generate().ToString();
            var headers   = new Dictionary <string, string>(options.OutgoingHeaders)
            {
                [Headers.MessageId] = messageId
            };

            var outgoingContext = new OutgoingReplyContext(
                new OutgoingLogicalMessage(messageType, message),
                messageId,
                headers,
                options.Context,
                context);

            return(pipeline.Invoke(outgoingContext));
        }
 public Guid Generate(SagaIdGeneratorContext context)
 {
     // intentionally ignore the property name and the value.
     return(CombGuid.Generate());
 }