[英]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
的订阅已经存在于其他一些主题中,门户网站给了我以下错误
@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.