代码之家  ›  专栏  ›  技术社区  ›  Tonyukuk

如何在azure上增加历元的大小

  •  1
  • Tonyukuk  · 技术社区  · 7 年前

    我该怎么做才能增加时代的规模?我发现以下错误:

    创建了具有更高历元“1544084492”的接收器,因此当前 纪元为“1544084474”的接收器正在断开连接。如果你是

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

    希望我是清楚的。

    谢谢你的帮助。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Murray Foxcroft    7 年前

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

    事件中心在内部将分区从一台主机移动到幕后的另一台主机。在这种情况下,在代码中使用简单的重试,这应该可以工作。为此,我使用 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());