我应该做什么来增加纪元的大小?我收到以下错误:
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/