【问题标题】:Increase deadline timeout for Google PubSub增加 Google PubSub 的截止时间超时
【发布时间】:2018-08-20 07:48:10
【问题描述】:

在使用 C# 库将消息发布到 Google PubSub 主题时,我们会间歇性地收到以下错误:

Exception: Grpc.Core.RpcException: Status(StatusCode=Unauthenticated, Detail="Deadline Exceeded")
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.PubSub.V1.Tasks.ForwardingAwaiter`1.GetResult()
   at Google.Cloud.PubSub.V1.Tasks.Extensions.<>c__DisplayClass6_0`1.<<ConfigureAwaitHideErrors>g__Inner0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.PubSub.V1.Tasks.ForwardingAwaiter`1.GetResult()
   at Google.Cloud.PubSub.V1.SimplePublisherImpl.<PublishAsync>d__26.MoveNext()
   at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass0_0`2.<<WithRetry>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

Google 告诉我的是可配置的超时。我们正在像这样配置客户端库:

private SimplePublisher CreateSimplePublisher(int maxItems, int maxSizeBytes, TimeSpan maxDelay)
{
    var credential = Credential.IsCreateScopedRequired ?
        Credential.CreateScoped(PublisherClient.DefaultScopes) : Credential;
    var channel = new Channel(
        PublisherClient.DefaultEndpoint.Host,
        PublisherClient.DefaultEndpoint.Port,
        credential.ToChannelCredentials());
    var publisherClient = PublisherClient.Create(channel);
    return SimplePublisher.Create(
        new TopicName(Project, Topic),
        new[] { publisherClient },
        new SimplePublisher.Settings
        {
            BatchingSettings = new BatchingSettings
            (
                elementCountThreshold: maxItems,
                byteCountThreshold: maxSizeBytes,
                delayThreshold: maxDelay
            )
        });
}

有谁知道如何在此配置中配置截止时间阈值?这是使用 Google.Cloud.PubSub.V1 客户端库 nuget 包的版本 1.0.0-beta13

【问题讨论】:

    标签: c# .net google-cloud-pubsub


    【解决方案1】:

    这似乎是通过将PublisherSettings 对象传递给PublisherClient.Create 调用来控制的。

    private SimplePublisher CreateSimplePublisher(int maxItems, int maxSizeBytes, TimeSpan maxDelay)
    {
        var credential = Credential.IsCreateScopedRequired ?
            Credential.CreateScoped(PublisherClient.DefaultScopes) : Credential;
        var channel = new Channel(
            PublisherClient.DefaultEndpoint.Host,
            PublisherClient.DefaultEndpoint.Port,
            credential.ToChannelCredentials());
        //Add a specific timeout for the publish operation
        var publisherClientSettings = new PublisherSettings
        {
            PublishSettings = CallSettings.FromCallTiming(CallTiming.FromTimeout(TimeSpan.FromMinutes(60)))
        };
        var publisherClient = PublisherClient.Create(channel,publisherClientSettings);
        return SimplePublisher.Create(
            new TopicName(Project, Topic),
            new[] { publisherClient },
            new SimplePublisher.Settings
            {
                BatchingSettings = new BatchingSettings
                (
                    elementCountThreshold: maxItems,
                    byteCountThreshold: maxSizeBytes,
                    delayThreshold: maxDelay
                )
            });
    }
    

    【讨论】:

    • 鉴于从 1.0.0-beta15 到 1.0.0-beta16 的更改,是否有更新的答案:“PublisherSettings 现在名为 PublisherServiceApiSettings”?
    猜你喜欢
    • 2023-03-20
    • 2017-07-07
    • 2010-10-31
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 2017-11-30
    • 2014-02-09
    • 2019-05-01
    相关资源
    最近更新 更多