Azure Event Hub超时 [英] Azure Event Hub timeouts

查看:117
本文介绍了Azure Event Hub超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试向Azure事件中心发送消息时,我有时会在事件中心客户端中看到超时错误.客户端似乎已达到资源限制,但是我不确定... 这里的代码:

I occasionally see timeout errors in event hub client when trying to send messages to Azure event hub. It looks like resource limit is reached for client but I'm not sure... Here the code:

   MessagingFactory messagingFactory = null;
            EventHubClient hubClient = null;

            try
            {
                messagingFactory = MessagingFactory.CreateFromConnectionString(this.connectionString);

                hubClient = messagingFactory.CreateEventHubClient(this.configurationManager.EventHubName);

                var batchIterator = new EventBatchIterator<T>(events);
                foreach (var batch in batchIterator)
                {
                    await hubClient.SendBatchAsync(batch);
                }
            }
            catch (Exception e)
            {
                this.logger.Error("An error occurred during sent messages to event hub", e);
            }
            finally
            {
                if (hubClient != null)
                {
                    await hubClient.CloseAsync();
                }

                if (messagingFactory != null)
                {
                    await messagingFactory.CloseAsync();
                }
            }

例外是:

与"N/A"通信时发生错误.检查 连接信息,然后重试. Microsoft.ServiceBus.Messaging.MessagingCommunicationException

An error occurred during communication with 'N/A'. Check the connection information, then retry. Microsoft.ServiceBus.Messaging.MessagingCommunicationException

连接尝试失败,因为被连接方未 一段时间后正确响应或建立连接 失败,因为连接的主机无法响应 System.Net.Sockets.SocketException

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond System.Net.Sockets.SocketException

推荐答案

根据您提到的execption指示用户启动的操作花费的时间比操作超时的时间长.我的解决方法是您可以增加OperationTimeout或重试计数.

According to you mentioned execption indicates that a user-initiated operation is taking longer than the operation timeout. My workaround is that you could increase OperationTimeout or retry count.

用于增加超时时间的演示代码

Demo code for increasing timeout

var builder = new ServiceBusConnectionStringBuilder("connection string")
                {
                    TransportType = TransportType.Amqp,
                    OperationTimeout = TimeSpan.FromSeconds(90)
                };

messagingFactory = MessagingFactory.CreateFromConnectionString(builder.ToString());

有关超时异常的更多信息,请参考此

More info about Timeout exception you refer to this document.

常见原因

此错误的常见原因有两种:错误的配置或暂时性的服务错误.

There are two common causes for this error: incorrect configuration, or a transient service error.

  • 错误的配置.对于操作条件,操作超时可能太小.客户端SDK中操作超时的默认值为 60秒.检查代码中的值是否设置得太小.请注意,网络状况和CPU使用情况会影响完成特定操作所需的时间,因此,操作超时不应设置为非常小的值.

  • Incorrect configuration The operation timeout might be too small for the operational condition. The default value for the operation timeout in the client SDK is 60 seconds. Check to see if your code has the value set to something too small. Note that the condition of the network and CPU usage can affect the time it takes for a particular operation to complete, so the operation timeout should not be set to a very small value.

暂时性服务错误:有时,事件中心服务可能会遇到处理请求的延迟;例如,在人流量大的时期.在这种情况下,您可以在延迟后重试操作,直到操作成功.如果多次尝试后同一操作仍然失败,请访问Azure服务状态网站以查看是否存在任何已知的服务中断.

Transient service error Sometimes the Event Hubs service can experience delays in processing requests; for example, during periods of high traffic. In such cases, you can retry your operation after a delay, until the operation is successful. If the same operation still fails after multiple attempts, please visit the Azure service status site to see if there are any known service outages.

这篇关于Azure Event Hub超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆