问题描述

在Azure中连接 Service Bus 服务发送消息时发生证书错误,抛出证书异常消息:

The X.509 certificate CN=servicebus.chinacloudapi.cn, OU=Azure, O=Shanghai Blue Cloud Technology Co Ltd, L=Shanghai, S=Shanghai, C=CN is not in the trusted people store.
The X.509 certificate CN=servicebus.chinacloudapi.cn, OU=Azure, O=Shanghai Blue Cloud Technology Co Ltd, L=Shanghai, S=Shanghai, C=CN chain building failed.
The certificate that was used has a trust chain that cannot be verified.
Replace the certificate or change the certificateValidationMode.
A certificate chain could not be built to a trusted root authority.

问题解答

如果在连接Service Bus的代码中不对 ConnectivityMode 做预先设置,Service Bus SDK默认使用了 AutoDetect 模式 连接 Service Bus 服务。

AutoDetect 会优先使用 TCP 连接模式,由于 TCP 连接模式也是加密的,所以客户端需要首先验证 service bus 服务器证书 CN = servicebus.chinacloudapi.cn 的有效性,证书链信息在 SSL 协议的 server hello 消息中返回。

如果证书链中的某些中间证书没有安装在 web 应用实例上,web 应用需要发起额外的请求到 CA 服务器上下载中间证书并安装。当下面任何一种情况发生时,web 应用无法对 service bus 服务器证书建立信任的证书链,随后会报告上述的证书错误:

  1. 运行Service Bus客户端代码的实例和 CA 服务器之间存在网络问题,导致无法下载证书.
  2. 运行Service Bus客户端代码的实例无法成功安装证书,如权限问题等。

推荐在代码中强制使用 HTTPS 模式连接 Service Bus 服务,HTTPS 模式有不同的设计,因此会很大程度上避免上述错误发生。

示例代码如下:

string connectionString = "servicebus connection string";

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https

var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

if (!namespaceManager.TopicExists("TestTopic"))
{
namespaceManager.CreateTopic("TestTopic");
} TopicClient client = TopicClient.CreateFromConnectionString(connectionString, "TestTopic"); BrokeredMessage testMessage = new BrokeredMessage("test message");
testMessage.MessageId = "message id"; client.Send(testMessage);

另外,以上代码代码使用很旧的Service Bus SDK,强烈建议升级SDK代码,使用新的AMQP协议连接Service Bus

using Azure.Messaging.ServiceBus;

// the client that owns the connection and can be used to create senders and receivers
ServiceBusClient client;
// The Service Bus client types are safe to cache and use as a singleton for the lifetime
// of the application, which is best practice when messages are being published or read
// regularly.
//
// set the transport type to AmqpWebSockets so that the ServiceBusClient uses the port 443.
// If you use the default AmqpTcp, you will need to make sure that the ports 5671 and 5672 are open // TODO: Replace the <NAMESPACE-CONNECTION-STRING> and <QUEUE-NAME> placeholders
var clientOptions = new ServiceBusClientOptions()
{
TransportType = ServiceBusTransportType.AmqpWebSockets
};
client = new ServiceBusClient("<NAMESPACE-CONNECTION-STRING>", clientOptions);

参考文档

添加将消息发送到队列的代码  : https://learn.microsoft.com/zh-cn/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues?tabs=passwordless#add-code-to-send-messages-to-the-queue

【Azure 服务总线】使用Azure Service Bus 时,出现证书错误: 所使用的证书具有无法验证的信任链的更多相关文章

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

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

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

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

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

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

  4. 【Azure 事件中心】在Service Bus Explorer工具种查看到EventHub数据在分区中的各种属性问题

    问题描述 通过Service Bus Explorer工具,查看到Event Hub的属性值,从而产生的问题及讨论: Size in Bytes:   这个是表示当前分区可以存储的最大字节数吗? La ...

  5. 使用Microsoft Azure云平台中的Service Bus 中继 Intanet环境下的WCF服务。

    之前写的一篇文章:) 看起来好亲切. http://www.cnblogs.com/developersupport/archive/2013/05/23/WCF-ON-IIS-Azure-Servi ...

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

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

  7. 【Azure Service Bus】 Service Bus如何确保消息发送成功,发送端是否有Ack机制 

    问题描述 Service Bus如何确保消息发送成功,发送端是否有Ack机制(是否有回调API告诉发送端,服务端已经收到消息)?根据对.NET发送Service Bus消息代码的分析,发送方法queu ...

  8. Azure Service Bus(二)在NET Core 控制台中如何操作 Service Bus Queue

    一,引言 上一篇讲到关于 Azure ServiceBus 的一些概念,讲到 Azure Service Bus(服务总线),其实也叫 "云消息服务",是微软在Azure 上提供的 ...

  9. Azure Service Bus(一)入门简介

    一,引言 今天开始学习新的内容 Azure Service Bus(服务总线),其实也叫 "云消息服务",和 RabbitMQ,KafKa的一样都是作为消息通信服务,但是它们直接还 ...

  10. Azure service bus Topic基本用法

    我们在升级一个POS系统的时候,决定使用微软公有云计算平台下的Azure ServiceBus 进行POS客户端与服务器的交互. 本文主要时作者在学习使用 Azure SDK for .NET 操作由 ...

随机推荐

  1. MAT的简单学习

    背景说明 Java遇到问题之后比较浅层的跟踪解决办法: jps 查看进程的main jar包 对应的进程信息 jstack 查看 堆栈信息 top -Hp PID 实时查看具体的CPU进程信息. 如果 ...

  2. locust+python性能测试库

    一.简介 locust官网介绍:Locust 是一个用于 HTTP 和其他协议的开源性能/负载测试工具.其对开发人员友好的方法允许您在常规 Python 代码中定义测试.Locust测试可以从命令行运 ...

  3. ElementUI实现表格(table) 行上下移动的效果

    参考地址 https://blog.csdn.net/sunshine0508/article/details/88390155 看大佬的地址 <div id="app"&g ...

  4. iframe 框架技术

    隐性转发 <!doctype html> <html lang="zh_CN"> <head> <meta charset="u ...

  5. python代码的tab和空格缩进互转

    代码规范 在我们项目中python代码使用tab缩进,并统一大家的编辑器设置. 如果同一个python文件中即有空格又有tab缩进,那么运行此文件会报错. 关于使用空格还是tab,这里就不展开讨论了, ...

  6. 从零开始配置vim(20)——模糊查询

    在讲解vim的基础功能的时候,介绍过了vim的各种查询技巧,在同一个文件中进行搜索的话,那些技巧很有用.在多个文件中我们介绍了使用vim自带的 :grep命令进行搜索,使用quickfix 列表进行跳 ...

  7. QAnything本地知识库问答系统:基于检索增强生成式应用(RAG)两阶段检索、支持海量数据、跨语种问答

    QAnything本地知识库问答系统:基于检索增强生成式应用(RAG)两阶段检索.支持海量数据.跨语种问答 QAnything (Question and Answer based on Anythi ...

  8. Python中局部放大图案例

    例子一: 先上完整代码和效果图: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.ins ...

  9. RabbitMQ高级知识(消息可靠性,死信交换机,惰性队列,MQ集群)

    服务异步通信-高级篇 消息队列在使用过程中,面临着很多实际问题需要思考: 1.消息可靠性 消息从发送,到消费者接收,会经历多个过程: 其中的每一步都可能导致消息丢失,常见的丢失原因包括: 发送时丢失: ...

  10. 解决线程不安全的方式(Java)

    一.同步代码块 package com.synchronized1; // 买票示例 // 使用同步代码块解决线程安全问题 public class TicketRunnableImp impleme ...