Exemplo n.º 1
0
        private void OnTransportMessageReceived(object sender, TransportMessageReceivedEventArgs e)
        {
            var         transportMessage = e.Message;
            var         timeoutId        = transportMessage.Headers["Timeout.Id"];
            TimeoutData timeoutData;

            if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData))
            {
                MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.Destination);
            }
        }
Exemplo n.º 2
0
        public bool Handle(TransportMessage message)
        {
            var         timeoutId = message.Headers["Timeout.Id"];
            TimeoutData timeoutData;

            if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData))
            {
                MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.Destination);
            }

            return(true);
        }
        public bool Handle(TransportMessage message)
        {
            var         timeoutId = message.Headers["Timeout.Id"];
            TimeoutData timeoutData;

            if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData))
            {
                MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.ToSendOptions(Configure.LocalAddress));
            }

            return(true);
        }
Exemplo n.º 4
0
        public void PushTimeout(TimeoutData timeout)
        {
            if (timeout.Time.AddSeconds(-1) <= DateTime.UtcNow)
            {
                MessageSender.Send(timeout.ToTransportMessage(), timeout.ToSendOptions(Configure.LocalAddress));
                return;
            }

            TimeoutsPersister.Add(timeout);

            if (TimeoutPushed != null)
            {
                TimeoutPushed(timeout);
            }
        }
Exemplo n.º 5
0
        public void PushTimeout(TimeoutData timeout)
        {
            if (timeout.Time.AddSeconds(-1) <= DateTime.UtcNow)
            {
                MessageSender.Send(timeout.ToTransportMessage(), timeout.Destination);
                return;
            }

            TimeoutsPersister.Add(timeout);

            if (TimeoutPushed != null)
            {
                TimeoutPushed.BeginInvoke(this, timeout, ar => {}, null);
            }
        }
Exemplo n.º 6
0
        public bool Handle(TransportMessage message)
        {
            var timeoutId = message.Headers["Timeout.Id"];

            var persisterV2 = TimeoutsPersister as IPersistTimeoutsV2;

            if (persisterV2 != null)
            {
                var timeoutData = persisterV2.Peek(timeoutId);
                if (timeoutData == null)
                {
                    return(true);
                }

                var sendOptions = timeoutData.ToSendOptions(Configure.LocalAddress);

                if (ShouldSuppressTransaction())
                {
                    sendOptions.EnlistInReceiveTransaction = false;
                }

                MessageSender.Send(timeoutData.ToTransportMessage(), sendOptions);

                return(persisterV2.TryRemove(timeoutId));
            }
            else
            {
                TimeoutData timeoutData;
                if (TimeoutsPersister.TryRemove(timeoutId, out timeoutData))
                {
                    MessageSender.Send(timeoutData.ToTransportMessage(), timeoutData.ToSendOptions(Configure.LocalAddress));
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        void Poll(object obj)
        {
            var cancellationToken = (CancellationToken)obj;

            var startSlice = DateTime.UtcNow.AddYears(-10);

            resetEvent.Reset();

            while (!cancellationToken.IsCancellationRequested)
            {
                if (nextRetrieval > DateTime.UtcNow)
                {
                    Thread.Sleep(SecondsToSleepBetweenPolls * 1000);
                    continue;
                }

                Logger.DebugFormat("Polling for timeouts at {0}.", DateTime.Now);

                DateTime nextExpiredTimeout;
                var      timeoutDatas = TimeoutsPersister.GetNextChunk(startSlice, out nextExpiredTimeout);

                foreach (var timeoutData in timeoutDatas)
                {
                    if (startSlice < timeoutData.Item2)
                    {
                        startSlice = timeoutData.Item2;
                    }

                    MessageSender.Send(CreateTransportMessage(timeoutData.Item1), new SendOptions(DispatcherAddress));
                }

                lock (lockObject)
                {
                    //Check if nextRetrieval has been modified (This means that a push come in) and if it has check if it is earlier than nextExpiredTimeout time
                    if (!timeoutPushed)
                    {
                        nextRetrieval = nextExpiredTimeout;
                    }
                    else if (nextExpiredTimeout < nextRetrieval)
                    {
                        nextRetrieval = nextExpiredTimeout;
                    }

                    timeoutPushed = false;
                }

                // we cap the next retrieval to max 1 minute this will make sure that we trip the circuit breaker if we
                // loose connectivity to our storage. This will also make sure that timeouts added (during migration) direct to storage
                // will be picked up after at most 1 minute
                var maxNextRetrieval = DateTime.UtcNow + TimeSpan.FromMinutes(1);

                if (nextRetrieval > maxNextRetrieval)
                {
                    nextRetrieval = maxNextRetrieval;
                }

                Logger.DebugFormat("Polling next retrieval is at {0}.", nextRetrieval.ToLocalTime());
                circuitBreaker.Success();
            }

            resetEvent.Set();
        }
Exemplo n.º 8
0
 public void RemoveTimeoutBy(Guid sagaId)
 {
     TimeoutsPersister.RemoveTimeoutBy(sagaId);
 }
Exemplo n.º 9
0
        public void RemoveTimeout(string timeoutId)
        {
            TimeoutData timeoutData;

            TimeoutsPersister.TryRemove(timeoutId, out timeoutData);
        }
        void Poll()
        {
            var pollingFailuresCount = 0;
            var startSlice           = DateTime.UtcNow.AddYears(-10);

            while (!stopRequested)
            {
                if (nextRetrieval > DateTime.UtcNow)
                {
                    Thread.Sleep(SecondsToSleepBetweenPolls * 1000);
                    continue;
                }

                try
                {
                    Logger.DebugFormat("Polling for timeouts at {0}.", DateTime.Now);

                    DateTime nextExpiredTimeout;
                    var      timeoutDatas = TimeoutsPersister.GetNextChunk(startSlice, out nextExpiredTimeout);

                    foreach (var timeoutData in timeoutDatas)
                    {
                        if (startSlice < timeoutData.Item2)
                        {
                            startSlice = timeoutData.Item2;
                        }

                        MessageSender.Send(CreateTransportMessage(timeoutData.Item1), TimeoutDispatcherProcessor.TimeoutDispatcherAddress);
                    }

                    lock (lockObject)
                    {
                        //Check if nextRetrieval has been modified (This means that a push come in) and if it has check if it is earlier than nextExpiredTimeout time
                        if (!timeoutPushed)
                        {
                            nextRetrieval = nextExpiredTimeout;
                        }
                        else if (nextExpiredTimeout < nextRetrieval)
                        {
                            nextRetrieval = nextExpiredTimeout;
                        }

                        timeoutPushed = false;
                    }

                    Logger.DebugFormat("Polling next retrieval is at {0}.", nextRetrieval.ToLocalTime());

                    pollingFailuresCount = 0;
                }
                catch (Exception ex)
                {
                    if (pollingFailuresCount >= 10)
                    {
                        Logger.Fatal("Polling of timeouts has failed the maximum number of times.", ex);
                        throw; //This should bring down the whole endpoint
                    }

                    Logger.Error("Polling of timeouts failed.", ex);

                    pollingFailuresCount++;
                }
            }
        }