简体   繁体   中英

how to increase size of the epoch at azure

What I am supposed to do to increase the size of the epoch ? I get following error:

com.microsoft.azure.eventhubs.ReceiverDisconnectedException: New receiver with higher epoch of '1544084492' is created hence current receiver with epoch '1544084474' is getting disconnected. If you are recreating the receiver, make sure a higher epoch is used.

Is this a problem which comes from azure or I have to change something at my test application ?

Hope I was clear.

Thank you for your helps.

There are two reasons for this, either:

You have two applications using the same consumer group to access the event hub. Either rework your architecture to have one client application, or use a new consumer group for each client. If you are trying to parallelise processing, pull a batch of events from the hub and then process them in parallel, don't have multiple readers on the same consumer group.

OR

Event hubs is internally moving partitions around from one host to another behind the scenes. In this case use a simply retry in your code and this should work. For this I use Polly . Actually, in practice, it is usually a good idea to wrap code calling "the cloud" in a retry.

A sample retry policy could be as follows (you need to include the Polly Nuget package ):

namespace RetryPolicies
{
    using Microsoft.Extensions.Logging;
    using Polly;
    using Polly.Retry;
    using System;

    public class ExponentialRetryManager
    {
        private static readonly int MAX_RETRIES = 6;
        private RetryPolicy _retryPolicy;

        /// <summary>
        /// An exponential retry manager that will wait as follows between retries:
        ///                     
        //  2 ^ 1 = 2 seconds first, then 
        //  2 ^ 2 = 4 seconds then
        //  2 ^ 3 = 8 seconds then
        //  2 ^ 4 = 16 seconds then
        //  2 ^ 5 = 32 seconds
        //  2 ^ 6 = 64 seconds
        /// </summary>
        public ExponentialRetryManager(ILogger logger, String exceptionName = null)
        {
            _retryPolicy = Policy
                .Handle<Exception>()
                .WaitAndRetry(MAX_RETRIES, retryAttempt =>
                TimeSpan.FromSeconds(Math.Pow(1, retryAttempt)),
                (ex, timeSpan, retryAttempt, context) =>
                {
                    logger.LogWarning($"Warning! [RetryAttempt={retryAttempt.ToString()}],[Ex={ex.ToString()}]");
                });
        }

        /// <summary>
        /// Executes the passed in action using the retry policy in order to
        /// keep attempting to process until the MAX_RETRIES are reached. 
        /// </summary>
        /// <param name="action"></param>
        public void Retry(Action action)
        {
            _retryPolicy.Execute(() => action());
        }
    }
}

and you call it as follows:

var retryManager = new ExponentialRetryManager(log);
retryManager.Retry(() => YourMethodToProcessEventHub());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM