Exemplo n.º 1
0
        /// <summary>
        /// Sends the message to the timeout manager, which will send it back after the specified
        /// time span has elapsed. Note that you must have a running timeout manager for this to
        /// work.
        /// </summary>
        public void Defer(TimeSpan delay, object message)
        {
            Guard.NotNull(message, "message");
            Guard.GreaterThanOrEqual(delay, TimeSpan.FromSeconds(0), "delay");

            if (configureAdditionalBehavior.OneWayClientMode && !HasHeaderFor(message, Headers.ReturnAddress))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Defer cannot be used when the bus is in OneWayClientMode, since there would be no" +
                              " destination for the TimeoutService to return to. You CAN defer messages in one-way" +
                              " mode though, if you explicitly specify a return address on the message with the" +
                              " {0} header",
                              Headers.ReturnAddress));
            }


            var attachedHeaders = headerContext.GetHeadersFor(message);
            var customData      = TimeoutReplyHandler.Serialize(new Message {
                Headers = attachedHeaders, Messages = new[] { message }
            });

            var timeoutRequest = new TimeoutRequest
            {
                Timeout       = delay,
                CustomData    = customData,
                CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId
            };

            if (MessageContext.HasCurrent)
            {
                var messageContext = MessageContext.GetCurrent();

                // if we're in a saga context, be nice and set the saga ID automatically
                if (messageContext.Items.ContainsKey(SagaContext.SagaContextItemKey))
                {
                    var sagaContext = ((SagaContext)messageContext.Items[SagaContext.SagaContextItemKey]);
                    timeoutRequest.SagaId = sagaContext.Id;
                }

                // if we're currently handling a message with a rebus message ID, transfer it to the deferred message
                if (!HasHeaderFor(message, Headers.MessageId))
                {
                    if (messageContext.Headers.ContainsKey(Headers.MessageId))
                    {
                        headerContext.AttachHeader(message, Headers.MessageId, messageContext.RebusTransportMessageId);
                    }
                }
            }

            var messages = new List <object> {
                timeoutRequest
            };

            InternalSend(new List <string> {
                timeoutManagerAddress
            }, messages);
        }
Exemplo n.º 2
0
        public void Defer(TimeSpan delay, object message)
        {
            var customData = TimeoutReplyHandler.Serialize(message);

            var messages = new List <object>
            {
                new TimeoutRequest
                {
                    Timeout       = delay,
                    CustomData    = customData,
                    CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId
                }
            };

            InternalSend("rebus.timeout", messages);
        }
Exemplo n.º 3
0
        public void Defer(TimeSpan delay, object message)
        {
            Guard.NotNull(message, "message");
            Guard.GreaterThanOrEqual(delay, TimeSpan.FromSeconds(0), "delay");

            var customData = TimeoutReplyHandler.Serialize(message);

            var messages = new List <object>
            {
                new TimeoutRequest
                {
                    Timeout       = delay,
                    CustomData    = customData,
                    CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId
                }
            };

            InternalSend(timeoutManagerAddress, messages);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends the message to the timeout manager, which will send it back after the specified
        /// time span has elapsed. Note that you must have a running timeout manager for this to
        /// work.
        /// </summary>
        public void Defer(TimeSpan delay, object message)
        {
            Guard.NotNull(message, "message");
            Guard.GreaterThanOrEqual(delay, TimeSpan.FromSeconds(0), "delay");

            if (busMode == BusMode.OneWayClientMode && !HasReturnAddressHeader(message))
            {
                throw new InvalidOperationException("Defer cannot be used when the bus is in OneWayClientMode, since there " +
                                                    "would be no destination for the TimeoutService to return to.");
            }

            var customData = TimeoutReplyHandler.Serialize(message);

            var timeoutRequest = new TimeoutRequest
            {
                Timeout       = delay,
                CustomData    = customData,
                CorrelationId = TimeoutReplyHandler.TimeoutReplySecretCorrelationId
            };

            if (MessageContext.HasCurrent)
            {
                var messageContext = MessageContext.GetCurrent();

                // if we're in a saga context, be nice and set the saga ID automatically
                if (messageContext.Items.ContainsKey(SagaContext.SagaContextItemKey))
                {
                    var sagaContext = ((SagaContext)messageContext.Items[SagaContext.SagaContextItemKey]);
                    timeoutRequest.SagaId = sagaContext.Id;
                }
            }

            var messages = new List <object> {
                timeoutRequest
            };

            InternalSend(timeoutManagerAddress, messages);
        }