问题描述

使用 Azure Service Bus,提供应用程序之间松耦合的消息交换,但是有时候发送消息多次出现超时错误。

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.

ErrorCode: TimedOut (ServiceCommunicationProblem)

为了预防这类偶发的Timedout异常对应用的影响,需要重新再次发送或接收消息,是否有内置的重试机制呢?

问题解答

有的,Service Bus的SDK有内置的重试机制,通过ServiceBusRetryOptions 配置。其中,默认的MaxRetries 次数为3次,每次重试的间隔时间默认为 60秒。

如在 .NET应用代码中使用示例:

using Azure.Messaging.ServiceBus;

string connectionString = "<connection_string>";
string queueName = "<queue_name>"; // Because ServiceBusClient implements IAsyncDisposable, we'll create it
// with "await using" so that it is automatically disposed for us.
var options = new ServiceBusClientOptions();
options.RetryOptions = new ServiceBusRetryOptions
{
Delay = TimeSpan.FromSeconds(10),
MaxDelay = TimeSpan.FromSeconds(30),
Mode = ServiceBusRetryMode.Exponential,
MaxRetries = 3,
};
await using var client = new ServiceBusClient(connectionString, options);

对于 Timeout 的异常,如果持续一小段(间断性)发送,可以通过 telnet 或 psping 来查看端口,网络稳定性。

# 测试端口,服务器是否能ping通
telnet <yournamespacename>.servicebus.chinacloudapi.cn 5671 #测试是否存在网络丢包问题
.\psping.exe -n 25 -i 1 -q <yournamespace>.servicebus.chinacloudapi.cn:5671 -nobanner

参考资料

Service Bus的重试策略:https://learn.microsoft.com/zh-cn/azure/architecture/best-practices/retry-service-specific#retry-mechanism-6

Service Bus Timeout 异常 :https://docs.azure.cn/zh-cn/service-bus-messaging/service-bus-troubleshooting-guide#connectivity-certificate-or-timeout-issues

Service Bus Socket 异常 :https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-exceptions#cause-2

【Azure 服务总线】Azure.Messaging.ServiceBus 多次发送消息报超时错误,是否可以配置重新发送?是否有内置重试机制?的更多相关文章

  1. 【Azure 服务总线】详解Azure Service Bus SDK中接收消息时设置的maxConcurrentCalls,prefetchCount参数

    (Azure Service Bus服务总线的两大类消息处理方式: 队列Queue和主题Topic) 问题描述 使用Service Bus作为企业消息代理,当有大量的数据堆积再Queue或Topic中 ...

  2. Windows Azure 服务总线和物联网

    机器到机器 (M2M) 计算正迅速成为一种技术,所有开发人员和架构师需要拥抱. 许多研究表明一个未来世界的数百亿美元的设备 (在地球上的每一个人的出现).MSDN杂志有2篇文章讨论Azure服务总线和 ...

  3. 【服务总线 Azure Service Bus】Service Bus在使用预提取(prefetching)后出现Microsoft.Azure.ServiceBus.MessageLockLostException异常问题

    问题描述 Service Bus接收端的日志中出现大量的MessageLockLostException异常.完整的错误消息为: Microsoft.Azure.ServiceBus.MessageL ...

  4. 【服务总线 Azure Service Bus】ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题

    Azure Service Bus 死信队列产生的原因 服务总线中有几个活动会导致从消息引擎本身将消息推送到 DLQ. 如 超过 MaxDeliveryCount 超过 TimeToLive 处理订阅 ...

  5. 【Azure 服务总线】Azure Service Bus中私信(DLQ - Dead Letter Queue)如何快速清理

    在博文ServiceBus 队列中死信(DLQ - Dead Letter Queue)问题一文中,介绍了服务总线产生私信的原因及可以通过代码的方式来清楚私信队列中的消息,避免长期占用空间(因为私信中 ...

  6. C# 消息队列-Microsoft Azure service bus 服务总线

    先决条件 Visual Studio 2015或更高版本.本教程中的示例使用Visual Studio 2015. Azure订阅. 注意 要完成本教程,您需要一个Azure帐户.您可以激活MSDN订 ...

  7. Azure Backup (2) Azure备份服务

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China. 本文介绍的Azure管理界面是Classic Model,网址:h ...

  8. C# Azure 消息队列ServiceBus (服务总线队列)

    1. 前言 在阅读本文之前,可以查看微软官方的说明. https://www.azure.cn/documentation/articles/service-bus-create-queues/ 2. ...

  9. Windows Azure HandBook (2) Azure China提供的服务

    <Windows Azure Platform 系列文章目录> 对于传统的自建数据中心,从底层的Network,Storage,Servers,Virtualization,中间层的OS, ...

  10. 在中国Windows Azure服务中创建应用程序的一些不同之处

    Azure 中的托管服务由一个应用程序(用于在托管服务中运行)和 XML 配置文件(定义托管服务的运行方式)组成.托管服务同时使用服务定义文件 (.csdef) 和配置文件 (.cscfg).有关详细 ...

随机推荐

  1. Kernel 内核支持的方法查询

    今天同事说自己的一个项目出现了报错如图: 报错的机器是 Windows XP 想找一个 windows XP的机器验证一下: 然后 想通过百度搜索确认一下 这个问题 但是发现基本上效果不大 改用了bi ...

  2. ELK运维文档

    Logstash 目录 Logstash Monitoring API Node Info API Plugins Info API Node Stats API Hot Threads API lo ...

  3. R2M分布式锁原理及实践

    作者:京东科技 张石磊 1 案例引入 名词简介: 资源:可以理解为一条内容,或者图+文字+链接的载体. 档位ID: 资源的分类组,资源必须归属于档位. 问题描述:当同一个档位下2条资源同时审批通过时, ...

  4. 如何去掉 node.js 获取MySQL数据产生的RowDataPacket

    如何去掉 node.js 获取MySQL数据产生的RowDataPacket 利用JSON.stringify()把对象转为对象字符串,可去掉RowDataPacket. router.post('/ ...

  5. vuex中action中发送数据

    state: { actionData: "", }, mutations: { actioncomAPi: (state, data) => { state.actionD ...

  6. RabbitMQ集成系统文章01---ABP VNext 分布式事务Event Bus 集成RabbitMQ

    1.在两个应用中都配置好要连接的RabbitMQ "RabbitMQ": { "Connections": { "Default": { & ...

  7. SpringSecurity 的登录流程

    ​ 用过SpringSecurity的小伙伴,都知道 Authentication 这个接口,我们在任何地方通过这个接口来获取到用户登录的信息,而我们用的频繁的一个它的一个实现类就是 Username ...

  8. Swift中常见的String用法,Array高阶使用,Set集合操作

    String字符串常见用法 生成字符串 创建字符串 let greeting = "Hello, world!" let name = String("John" ...

  9. Asp.net平台常用的框架整理

    分布式缓存框架: Microsoft Velocity:微软自家分布式缓存服务框架. Memcahed:一套分布式的高速缓存系统,目前被许多网站使用以提升网站的访问速度. Redis:是一个高性能的K ...

  10. VB6的Office颜色菜单 - 开源研究系列文章

    今天把VB6里面的源码开源了( VB6各类源码开源 - 开源研究系列文章 ),这次把原来VB6里面的一个菜单控件进行介绍,需要的网友请下载安装: 1.看使用截图: 运行时截图: 设计时截图: 2.Of ...