I have a Spring Boot application in which I am reading messages from a Azure service bus queue. Now I need to write another listener which will read message from a topic. Here both queue and topics have different namespace so I am facing issues in merging the configuration for both in application.yml file.
I need to connect to 2 ServiceBus which have different namespace from single SpringBoot application. I am using passwordless-enabled: true so not using connection string One namespace is for a queue and another namespace is for topic.
pom.xml
<spring-cloud-azure.version>4.17.0</spring-cloud-azure.version>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter</artifactId>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>4.17.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
application.yml
spring:
jms:
listener:
receive-timeout: 60000
servicebus:
namespace: topic-namespace
passwordless-enabled: true
pricing-tier: standard
enabled: true
topic-client-id: 5e78-4034-a948-44e819798c12
topic-name: topic-name
subscription-name: topic-cription-dev
---
spring:
jms:
listener:
receive-timeout: 60000
servicebus:
namespace: queue-namespace
passwordless-enabled: true
topic-client-id: 4b41-9a94-67cc176e1f74
pricing-tier: standard
queue-name: queue-name
enabled: true
spring.cloud.azure:
credential:
client-id: 4261-aa28-d150ffafe565
client-secret: .So13hhZ1b3V
profile:
tenant-id: ef0-43ca-a603-a8a1e287fa9d
QueueListner
@JmsListener(destination = "${spring.jms.servicebus.queue-name}", containerFactory = "jmsListenerContainerFactory")
public void receiveMessage(byte[] message) {
log.info("Queue Message received: {}", new String(message));
}
TopicListner
@JmsListener(destination = "${spring.jms.servicebus.topic-name}",
subscription = "${spring.jms.servicebus.subscription-name}",
containerFactory = "topicJmsListenerContainerFactory")
public void receiveMessage(String message) {
log.info("Message received: {}", message);
}
While looking for its solution, I found this-
This example explains how we can bind to two Service Bus namespaces separately through a queue binder and a topic binder.