azure - 如何增加azure中纪元的大小

标签 azure azure-eventhub

我应该做什么来增加纪元的大小?我收到以下错误:

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.

这是来自 azure 的问题还是我必须在我的测试应用程序中更改某些内容?

希望我说得清楚。

感谢您的帮助。

最佳答案

造成这种情况的原因有两个:

您有两个应用程序使用同一使用者组来访问事件中心。要么重新设计您的架构以拥有一个客户端应用程序,要么为每个客户端使用一个新的使用者组。如果您尝试并行处理,请从中心提取一批事件,然后并行处理它们,同一消费者组上不要有多个读取器。

或者

事件中心在内部将分区从一台主机移动到另一台主机。在这种情况下,只需在代码中重试即可,这应该可行。为此,我使用 Polly 。实际上,在实践中,将调用“云”的代码包装在重试中通常是一个好主意。

示例重试策略可能如下(您需要包含 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());
        }
    }
}

你可以这样调用它:

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

关于azure - 如何增加azure中纪元的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53652400/

相关文章:

javascript - 找不到模块 azure 函数 double_edge.js

azure - 具有多个 Azure Web 应用程序的 SSO

asp.net-mvc - Azure 云服务的保留 IP 地址不起作用

azureservicebus - 超出了 Azure 服务总线 SDK 的 SendBatch() 方法上的链接异常当前允许的限制(262144 字节)

amazon-web-services - 有没有办法将数据从 AWS Kinesis 发送到 Azure 事件中心?

azure - 本地运行 Azure function(V2) 时抛出 Newtonsoft.Json.JsonReaderException

azure - 无法在 Azure 中启用 "Microsoft.Container Service"

c# - Azure Functions EventHub 触发器连接字符串

c# - 将消息定向给消费者

azure - 从分区事件中心消费以避免 QuotaExceededException 的正确策略是什么?