This sample project demonstrates how to enable shared subscription using Spring JMS Topic for Azure Service Bus via Spring Boot Starter azure-spring-boot-starter-servicebus-jms
.
-
Add below code snippet in
AzureSpringBootSampleServicebusJmsTopicApplication.java
to get the bean oftopicJmsListenerContainerFactory
and modify its configuration.@Autowired private ApplicationContext applicationContext; @PostConstruct public void registerResources() { ((DefaultJmsListenerContainerFactory)applicationContext.getBean("topicJmsListenerContainerFactory")) .setSubscriptionShared(Boolean.TRUE); }
-
Update application.properties
# Fill service bus namespace connection string copied from portal spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] # The JMS client id needs to be specified when using topic and durable subscription # Default is empty string spring.jms.servicebus.topic-client-id=[topic-client-id] # The idle timeout in milliseconds after which the connection will be failed if the peer sends no AMQP frames # Default is 1800000 spring.jms.servicebus.idle-timeout=[idle-timeout] #Fill service bus pricing tier according to the one you created. Supported values are premium and standard. spring.jms.servicebus.pricing-tier=[pricing-tier]
-
Specify your topic name and subscription name. Update
TOPIC_NAME
in TopicSendController and TopicReceiveController, andSUBSCRIPTION_NAME
in TopicReceiveController.
-
Run with Maven:
mvn spring-boot:run
-
Send a POST request to service bus topic.
$ curl -X POST localhost:8080/topic?message=hello
-
Verify in your app's logs that a similar message was posted:
Sending message Received message from topic: hello