Пример #1
0
        public void InvokeChannelAction(Action <IModel> channelAction)
        {
            Preconditions.CheckNotNull(channelAction, "channelAction");

            var timeout = TimeBudget.Start(configuration.GetTimeout());

            var retryTimeoutMs = MinRetryTimeoutMs;

            while (!timeout.IsExpired())
            {
                try
                {
                    var channel = OpenChannel();
                    channelAction(channel);
                    return;
                }
                catch (OperationInterruptedException exception)
                {
                    CloseChannel();
                    if (NeedRethrow(exception))
                    {
                        throw;
                    }
                }
                catch (EasyNetQException)
                {
                    CloseChannel();
                }

                Thread.Sleep(retryTimeoutMs);

                retryTimeoutMs = Math.Min(retryTimeoutMs * 2, MaxRetryTimeoutMs);
            }

            logger.Error("Channel action timed out");
            throw new TimeoutException("The operation requested on PersistentChannel timed out");
        }