简体   繁体   English

如何将 Springboot 应用程序连接到 Azure SB,具有跨不同主题的多个订阅(同名)

[英]How to connect a Springboot app to an Azure SB with multiple subscriptions (with same name) across different topics

I have a Controller in a Springboot app connecting to an Azure Service Bus using JMSListeners.我在使用 JMSListeners 连接到 Azure 服务总线的 Springboot 应用程序中有一个 Controller。

Method 1:

@JmsListener(destination = "${topicX}", containerFactory = "topicJmsListenerContainerFactory",
            subscription = "${XXX}")

Method 2:

@JmsListener(destination = "${topicY}", containerFactory = "topicJmsListenerContainerFactory",
        subscription = "${XXX}")

As you can see, the topic names are different, but subscription name is the same.如您所见,主题名称不同,但订阅名称相同。

I get an error in the Springboot app as it's starting up. Springboot 应用程序启动时出现错误。

Here's the error:这是错误:

Caused by: javax.jms.JMSRuntimeException: A non-shared durable subscription is already active with name 'XXX'.原因:javax.jms.JMSRuntimeException:非共享持久订阅已处于活动状态,名称为“XXX”。

I am new to Azure SB and topics, so I am not sure if this is something that is even possible to do?我是 Azure SB 和主题的新手,所以我不确定这是否可以做到? Or are multiple subscriptions under different topics not supposed to be named the same?或者不同主题下的多个订阅不应该被命名为相同的?

This is some code I've inherited to debug and find out what the solution might be, so I don't have much details as to why it was done this way.这是我继承的一些代码,用于调试并找出可能的解决方案,所以我没有太多关于为什么这样做的细节。 If you need any more information, I am happy to share.如果您需要更多信息,我很乐意与您分享。

Please help!请帮忙!

I've tried by commenting out 1 of the methods and confirmed it's working.我尝试通过注释掉其中一种方法并确认它有效。

I want to understand if there is a way to run both methods without errors.我想了解是否有办法在没有错误的情况下运行这两种方法。

  • As far as I know every subscription is distinct in a Service Bus Namespace.据我所知,每个订阅在服务总线命名空间中都是不同的。

  • Here I was trying to create a new subscription in a different topic while a subscription by the name Subscription already existed in some other topic the portal gave me the following error在这里,我试图在不同的主题中创建一个新的订阅,而名为Subscription的订阅已经存在于其他一些主题中,门户网站给了我以下错误

在此处输入图像描述

  • So I the only way to get message is with distinct subscriptions using the following code:所以我获取消息的唯一方法是使用以下代码进行不同的订阅:
@Component  
public class TopicReceiveController {  
    private static final String TOPIC_NAME1 = "test";  
 private static final String TOPIC_NAME2 = "newtest";  
 private static final String SUBSCRIPTION_NAME1 = "Subscription";  
 private static final String SUBSCRIPTION_NAME2 = "Subscription2";  
  
 private final Logger logger = LoggerFactory.getLogger(TopicReceiveController.class);  
  
  @JmsListener(destination = TOPIC_NAME1, containerFactory = "topicJmsListenerContainerFactory",  
  subscription = SUBSCRIPTION_NAME1)  
    public void receiveMessage(String Name) {  
        logger.info("Received message: {}", Name);  
  }  
  
    @JmsListener(destination = TOPIC_NAME2, containerFactory = "topicJmsListenerContainerFactory",  
  subscription = SUBSCRIPTION_NAME2)  
    public void receiveMessageNewTopic(String Name) {  
        logger.info("Received message: {}", Name);  
  }  
}

Output: Output:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Spring Boot App 连接到运行在不同主机上的多个 Google spanner 数据库 - How to Connect to Multiple Google spanner DB running on different host from Spring Boot App 如何使用 aws ec2 create-tags(来自 aws cli)跨多个资源为同一标签赋予不同的值? - How to use aws ec2 create-tags (from aws cli) to give different values to the same tag across multiple resources? 跨订阅共享 VNet? - Share a VNet across subscriptions? 如何跨多个谷歌云项目执行相同的查询并将结果保存在同一个表中? - How to execute the same query across multiple google cloud projets and save the result in same table? 如何在同一个 Azure Web 应用服务上部署 Blazor (WASM) 应用和一个 API? - How to deploy Blazor (WASM) app and an API on the same Azure Web App Service? Firestore 跨多个字段查询相同的值 - Firestore Query Across Multiple Fields for Same Value 来自不同区域的多个 API 具有相同自定义名称和不同基本路径的网关 - Multiple API Gateways from different regions with the same Custom Name and different base path 如何获取 Azure 环境名称 - How to get Azure Environment name 如何将相同的域名分配给 2 个 App Engine 实例? - How do I assign the same domain name to 2 App Engine Instances? 如何将数据库连接到 Azure Blob 中的数据文件? - How to connect database to data files in Azure Blob?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM