Ejemplo n.º 1
0
 public RetryProcessor(IBodyStorage bodyStorage, ISendMessages sender, IDocumentStore store, IBus bus, ReturnToSenderDequeuer returnToSender)
 {
     executor = new PeriodicExecutor(Process, TimeSpan.FromSeconds(30), ex => Log.Error("Error during retry batch processing", ex));
     this.bodyStorage = bodyStorage;
     this.sender = sender;
     this.store = store;
     this.bus = bus;
     this.returnToSender = returnToSender;
 }
Ejemplo n.º 2
0
        public static void HandleMessage(TransportMessage message, IBodyStorage bodyStorage, ISendMessages sender) //Public for testing
        {
            message.Headers.Remove("ServiceControl.Retry.StagingId");

            string attemptMessageId;

            if (message.Headers.TryGetValue("ServiceControl.Retry.Attempt.MessageId", out attemptMessageId))
            {
                Stream stream;
                if (bodyStorage.TryFetch(attemptMessageId, out stream))
                {
                    using (stream)
                    {
                        message.Body = ReadFully(stream);
                    }
                }
                message.Headers.Remove("ServiceControl.Retry.Attempt.MessageId");
            }
            var destination = message.Headers["ServiceControl.TargetEndpointAddress"];

            try
            {
                string retryTo;
                if (!message.Headers.TryGetValue("ServiceControl.RetryTo", out retryTo))
                {
                    retryTo = destination;
                    message.Headers.Remove("ServiceControl.TargetEndpointAddress");
                }

                sender.Send(message, new SendOptions(retryTo));
            }
            catch (Exception)
            {
                message.Headers["ServiceControl.TargetEndpointAddress"] = destination;
                if (attemptMessageId != null)
                {
                    message.Headers["ServiceControl.Retry.Attempt.MessageId"] = attemptMessageId;
                }

                throw;
            }
        }
Ejemplo n.º 3
0
        public ReturnToSenderDequeuer(IBodyStorage bodyStorage, ISendMessages sender, IDocumentStore store, IBus bus, Configure configure)
        {
            this.sender      = sender;
            this.bodyStorage = bodyStorage;

            Action executeOnFailure = () =>
            {
                if (IsCounting)
                {
                    CountMessageAndStopIfReachedTarget();
                }
                else
                {
                    timer.Change(TimeSpan.FromSeconds(45), Timeout.InfiniteTimeSpan);
                }
            };

            faultManager = new CaptureIfMessageSendingFails(store, bus, executeOnFailure);
            timer        = new Timer(state => StopInternal());
            InputAddress = Address.Parse(configure.Settings.EndpointName()).SubScope("staging");
        }
Ejemplo n.º 4
0
 public ReturnToSender(IBodyStorage bodyStorage)
 {
     this.bodyStorage = bodyStorage;
 }
Ejemplo n.º 5
0
 public TestReturnToSenderDequeuer(IBodyStorage bodyStorage, ISendMessages sender, IDocumentStore store, IDomainEvents domainEvents, Configure configure)
     : base(bodyStorage, sender, store, domainEvents, configure)
 {
 }
Ejemplo n.º 6
0
 public GetBodyByIdApi(IDocumentStore documentStore, IBodyStorage bodyStorage)
 {
     this.documentStore = documentStore;
     this.bodyStorage   = bodyStorage;
 }
Ejemplo n.º 7
0
 public BodyStorageEnricher(IBodyStorage bodyStorage, Settings settings)
 {
     this.bodyStorage = bodyStorage;
     this.settings    = settings;
 }
Ejemplo n.º 8
0
 public FakeReturnToSender(IBodyStorage bodyStorage, MyContext myContext) : base(bodyStorage)
 {
     this.myContext = myContext;
 }
        public static void HandleMessage(TransportMessage message, IBodyStorage bodyStorage, ISendMessages sender) //Public for testing
        {
            message.Headers.Remove("ServiceControl.Retry.StagingId");

            Log.DebugFormat("{0}: Retrieving message body", message.Id);

            string attemptMessageId;

            if (message.Headers.TryGetValue("ServiceControl.Retry.Attempt.MessageId", out attemptMessageId))
            {
                Stream stream;
                if (bodyStorage.TryFetch(attemptMessageId, out stream))
                {
                    using (stream)
                    {
                        message.Body = ReadFully(stream);
                    }
                }
                else
                {
                    Log.WarnFormat("{0}: Message Body not found for attempt Id {1}", message.Id, attemptMessageId);
                }
                message.Headers.Remove("ServiceControl.Retry.Attempt.MessageId");
            }
            else
            {
                Log.WarnFormat("{0}: Can't find message body. Missing header ServiceControl.Retry.Attempt.MessageId", message.Id);
            }

            if (message.Body != null)
            {
                Log.DebugFormat("{0}: Body size: {1} bytes", message.Id, message.Body.LongLength);
            }
            else
            {
                Log.DebugFormat("{0}: Body is NULL", message.Id);
            }

            var destination = message.Headers["ServiceControl.TargetEndpointAddress"];

            Log.DebugFormat("{0}: Forwarding message to {1}", message.Id, destination);
            try
            {
                string retryTo;
                if (!message.Headers.TryGetValue("ServiceControl.RetryTo", out retryTo))
                {
                    retryTo = destination;
                    message.Headers.Remove("ServiceControl.TargetEndpointAddress");
                }
                else
                {
                    Log.DebugFormat("{0}: Found ServiceControl.RetryTo header. Rerouting to {1}", message.Id, retryTo);
                }

                sender.Send(message, new SendOptions(retryTo));
                Log.DebugFormat("{0}: Forwarded message to {1}", message.Id, retryTo);
            }
            catch (Exception)
            {
                Log.WarnFormat("{0}: Error forwarding message, resetting headers", message.Id);
                message.Headers["ServiceControl.TargetEndpointAddress"] = destination;
                if (attemptMessageId != null)
                {
                    message.Headers["ServiceControl.Retry.Attempt.MessageId"] = attemptMessageId;
                }

                throw;
            }
        }
Ejemplo n.º 10
0
 public BodyStorageEnricher(IBodyStorage bodyStorage)
 {
     this.bodyStorage = bodyStorage;
 }