public void Run() { if (TimeoutManager == null) { return; } TimeoutManager.SagaTimedOut += (o, e) => { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { MessageSender.Send(MapToTransportMessage(e), e.Destination); Persister.Remove(e.SagaId); scope.Complete(); } }; Persister.GetAll().ToList().ForEach(td => TimeoutManager.PushTimeout(td)); thread = new Thread(Poll); thread.Start(); }
void HandleInternal(TransportMessage 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"); } TimeoutManager.RemoveTimeoutBy(sagaId); } else { string expire; if (!message.Headers.TryGetValue(TimeoutManagerHeaders.Expire, out expire)) { throw new InvalidOperationException("Non timeout message arrived at the timeout manager, id:" + message.Id); } var destination = message.ReplyToAddress; string routeExpiredTimeoutTo; if (message.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo)) { destination = Address.Parse(routeExpiredTimeoutTo); } var data = new TimeoutData { Destination = destination, SagaId = sagaId, State = message.Body, Time = DateTimeExtensions.ToUtcDateTime(expire), CorrelationId = GetCorrelationIdToStore(message), Headers = message.Headers, OwningTimeoutManager = Configure.EndpointName }; //add a temp header so that we can make sure to restore the ReplyToAddress if (message.ReplyToAddress != null) { data.Headers[TimeoutData.OriginalReplyToAddress] = message.ReplyToAddress.ToString(); } TimeoutManager.PushTimeout(data); } }
void CacheExistingTimeouts() { var sw = new Stopwatch(); sw.Start(); Logger.DebugFormat("Going to fetch existing timeouts from persister ({0})", Persister.GetType().Name); var existingTimeouts = Persister.GetAll().ToList(); Logger.DebugFormat("{0} timeouts loaded from storage in {1} seconds", existingTimeouts.Count, sw.Elapsed.TotalSeconds); existingTimeouts.ForEach(td => TimeoutManager.PushTimeout(td)); sw.Stop(); Logger.DebugFormat("Total time for cache priming {0} seconds", sw.Elapsed.TotalSeconds); }