This sample project demonstrates how to use Spring JMS for Azure Service Bus Queue via Spring Boot Starter azure-servicebus-jms-spring-boot-starter.
Running this sample will be charged by Azure. You can check the usage and bill at this link.
-
An Azure subscription. If you don't already have an Azure subscription, you can activate your MSDN subscriber benefits or sign up for a free Azure account.
-
A Java Development Kit (JDK), version 1.8.
-
Apache Maven, version 3.0 or later.
-
Go to Azure portal and create the service by following this link.
-
Update application.properties
# Fill service bus namespace connection string copied from portal spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] # 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] -
Specify your queue name. Update
QUEUE_NAMEin QueueSendController and QueueReceiveController.
-
Run the
mvn clean spring-boot:runin the root of the code sample to get the app running. -
Send a POST request to service bus queue.
$ curl -X POST localhost:8080/queue?message=hello -
Verify in your app's logs that a similar message was posted:
Sending message Received message from queue: hello -
Delete the resources on Azure Portal to avoid extra charges.
Please check the following table for reference links of detailed Service Bus usage.
| Type | Reference Link |
|---|---|
Queues |
https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-java-how-to-use-queues |