【Azure Service Bus】使用Spring Cloud integration示例代码,为多个 Service Bus的连接使用 ConnectionString 方式
问题描述
查看Service Bus的Java示例代码,发现使用Spring Cloud Integration,配置 Application.yaml 可以连接到两个Service Bus。 但代码中没有使用Connection String 属性配置服务连接。

那么,是否可以直接在此添加 connection-string配置后,不用修改代码就可以连接到Service Bus服务呢?
问题解答
在解答这个问题之前,需要查看示例代码中,是如何来使用application.yaml中的属性值。
1) 自定义 CustomizedServiceBusProperties 对象,结构化 应用的属性配置
2) 在 MultipleAzureServiceBusNamespacesConfiguration 中读取配置,并调用 com.azure.spring.messaging.servicebus.core.DefaultServiceBusNamespaceProcessorFactory 构造函数

接下来,就需要查看com.azure.spring.messaging.servicebus.core.DefaultServiceBusNamespaceProcessorFactory的构造函数是否可以使用connction string属性初始化 Service Bus Processor对象。
查看 DefaultServiceBusNamespaceProcessorFactory 类的介绍文档:https://azuresdkdocs.blob.core.windows.net/$web/java/spring-messaging-azure-servicebus/4.1.0/com/azure/spring/messaging/servicebus/core/DefaultServiceBusNamespaceProcessorFactory.html#createProcessor(java.lang.String,com.azure.spring.cloud.service.listener.MessageListener,com.azure.spring.cloud.service.servicebus.consumer.ServiceBusErrorHandler)
构造函数由 NamespaceProperties 类传递参数, 它拥有GetConnectionStrng方法可以直接读取connection-string属性值
getConnectionString
public String getConnectionString()Specified by:
getConnectionString in interface com.azure.spring.cloud.core.provider.connectionstring.ConnectionStringProviderSpecified by:
getConnectionString in interface com.azure.spring.cloud.service.implementation.servicebus.properties.ServiceBusClientCommonProperties
根据以上分析,如果需要Spring Cloud Integration示例代码使用连接字符串(Connection String) 初始化 Service Bus对象,只要在Application.yaml 文件中使用connection-string并设置正确的值就可以。
my.servicebus.namespaces[0]:
connection-string: {AZURE_SERVICEBUS_CONNECTION_STRING_01}
entity-type: queue
entity-name: {AZURE_SERVICEBUS_NAMESPACE_01_QUEUE_NAME}
my.servicebus.namespaces[1]:
connection-string: {AZURE_SERVICEBUS_CONNECTION_STRING_02}
entity-type: queue
entity-name: {AZURE_SERVICEBUS_NAMESPACE_02_QUEUE_NAME}
参考资料
Sending and Receiving Message by Azure Service Bus (Multiple Namespaces) And Spring Integration in Spring Boot Application :https://github.com/Azure-Samples/azure-spring-boot-samples/tree/main/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces
Class DefaultServiceBusNamespaceProcessorFactory : https://azuresdkdocs.blob.core.windows.net/$web/java/spring-messaging-azure-servicebus/4.1.0/com/azure/spring/messaging/servicebus/core/DefaultServiceBusNamespaceProcessorFactory.html
【Azure Service Bus】使用Spring Cloud integration示例代码,为多个 Service Bus的连接使用 ConnectionString 方式的更多相关文章
- Spring Cloud Bus介绍--Spring Cloud学习第七天(非原创)
一.什么是Spring Cloud Bus二.Spring Cloud Bus之RabbitMQ介绍三.Spring Cloud Bus整合RabbitMQ四.Spring Cloud Bus整合Ka ...
- Spring Cloud实战的代码和视频位置
大家好,本博文的连接里包含了Spring Cloud实战的代码和视频位置. 代码下载连接: 视频下载连接:
- Spring Cloud Zuul网关 Filter、熔断、重试、高可用的使用方式。
时间过的很快,写springcloud(十):服务网关zuul初级篇还在半年前,现在已经是2018年了,我们继续探讨Zuul更高级的使用方式. 上篇文章主要介绍了Zuul网关使用模式,以及自动转发机制 ...
- Spring Cloud Gateway 之获取请求体(Request Body)的几种方式
Spring Cloud Gateway 获取请求体 一.直接在全局拦截器中获取,伪代码如下 private String resolveBodyFromRequest(ServerHttpReque ...
- Spring Cloud Gateway 远程代码执行漏洞(CVE-2022-22947)
参考: https://y4er.com/post/cve-2022-22947-springcloud-gateway-spel-rce-echo-responsehttps://cloud.spr ...
- [Spring cloud 一步步实现广告系统] 6. Service实现&Zuul配置&Test
DAO层设计实现 这里我们使用Spring DATA JPA来实现数据库操作,当然大家也可以使用Mybatis,都是一样的,我们依然以用户表操作为例: /** * AdUserRepository f ...
- Spring Cloud(十一):Spring Cloud Zuul网关 Filter、熔断、重试、高可用的使用方式
上篇文章主要介绍了Zuul网关使用模式,以及自动转发机制,但其实Zuul还有更多的应用场景,比如:鉴权.流量转发.请求统计等等,这些功能都可以使用Zuul来实现. Zuul的核心 Filter是Zuu ...
- spring cloud深入学习(十二)-----Spring Cloud Zuul网关 Filter、熔断、重试、高可用的使用方式
Zuul的核心 Filter是Zuul的核心,用来实现对外服务的控制.Filter的生命周期有4个,分别是“PRE”.“ROUTING”.“POST”.“ERROR”,整个生命周期可以用下图来表示. ...
- 【Azure Spring Cloud】Azure Spring Cloud服务,如何获取应用程序日志文件呢?
问题描述 在使用Azure Spring Cloud服务时,如果要收集应用程序的日志.有控制台输出(实时流日志),也可以配置Log Analytics服务. 日志流式处理 可以通过以下命令在 Azur ...
- Spring Cloud 网关服务 zuul 三 动态路由
zuul动态路由 网关服务是流量的唯一入口.不能随便停服务.所以动态路由就显得尤为必要. 数据库动态路由基于事件刷新机制热修改zuul的路由属性. DiscoveryClientRouteLocato ...
随机推荐
- [转帖]【redis】redis各稳定版本特性(更新到6.0版本)
1.Redis2.6 Redis2.6在2012年正是发布,经历了17个版本,到2.6.17版本,相对于Redis2.4,主要特性如下: 1)服务端支持Lua脚本. 2)去掉虚拟内存相关功能. 3)放 ...
- C# 使用RabbitMQ消息队列
参考文章 https://www.cnblogs.com/kiba/p/11703073.html和https://www.cnblogs.com/longlongogo/p/6489574.html ...
- TienChin 渠道管理-渠道导出
ChannelController /** * 导出渠道列表 */ @PreAuthorize("hasPermission('tienchin:channel:export')" ...
- AspnetCore接入Nacos配置中心
一.什么是nacos Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生应用的动态服务发现.配置管理 ...
- 【3】VSCode 主题设置推荐,自定义配色方案,修改注释高亮颜色
相关文章: [一]tensorflow安装.常用python镜像源.tensorflow 深度学习强化学习教学 [二]tensorflow调试报错.tensorflow 深度学习强化学习教学 [三]t ...
- spark读取空orc文件时报错java.lang.RuntimeException: serious problem at OrcInputFormat.generateSplitsInfo
问题复现: G:\bigdata\spark-2.3.3-bin-hadoop2.7\bin>spark-shell 2020-12-26 10:20:48 WARN NativeCodeLoa ...
- 苹果iOS 17.2年底推送:iPhone 15 Pro的自定义操作按钮功能升级
据报道,苹果会在年底推送iOS 17.2版本,新版系统将会修复iPhone 15系列WiFi速度慢的问题. 与此同时,iOS 17.2将会带来翻译功能,iPhone 15 Pro的自定义操作按钮切换到 ...
- PHP 编程技巧与优化
PHP 编程技巧与优化 1. 尽量采用大量的PHP内置函数. 2. 使用echo代替print,并且使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接 3. 用单引号代替双引号来包含字符 ...
- Google三驾马车之二:MapReduce
第一次接触mr还是在入门mit6.824的lab1,最近重新读了一遍原始论文,又有了一些新的想法,简单做一些记录. 作为Google分布式系统的重要组成,本篇文章核心在于map/reduce操作带来的 ...
- JS Leetcode 451. 根据字符出现频率排序题解分析
壹 ❀ 引 大前天做的一道题,昨天发版到11点,前天聚餐,一直没时间整理,今天下班闲来无事,还是做个简单思路整理.本题来自LeetCode 451. 根据字符出现频率排序,难度中等,其实整理下思路,其 ...