This code sample demonstrates how to use Spring Integration for Azure Service Bus to receive messages from one queue in a Service Bus namespace and then forward them to a queue in another Service Bus namespace.
Running this sample will be charged by Azure. You can check the usage and bill at this link.
-
Create two Azure Service Bus namespaces and queues. Please see how to create.
-
[Optional] if you want to use managed identity, please follow create managed identity to set up managed identity.
- Update application.yaml with the required information of the Service Bus namespace used to receive messages from.
spring: cloud: azure: msi-enabled: true client-id: [the-id-of-managed-identity] resource-group: [resource-group] subscription-id: [subscription-id] # Uncomment below configurations if you want to enable auto creating resources. # # subscription-id: [subscription-id] # auto-create-resources: true # environment: Azure # region: [region] servicebus: namespace: [servicebus-namespace]
- Update QueueReceiveController.java
Constant Name | Constant meaning |
---|---|
INPUT_QUEUE_NAME | Name of the Queue in Service Bus namespace 1 to receive messages from |
OUTPUT_QUEUE_NAME | Name of the Queue in Service Bus namespace 2 to forward messages to |
OUTPUT_SERVICEBUS_MSI_CLIENT_ID | MSI of the Service Bus namespace 2 |
OUTPUT_SERVICEBUS_FQDN | Fully qualified domain name of Service Bus namespace 2 |
If you want to auto create the Azure Service Bus instances, make sure you add such properties (only support the service principal and managed identity cases):
spring:
cloud:
azure:
subscription-id: [subscription-id]
auto-create-resources: true
environment: Azure
region: [region]
-
Run the
mvn spring-boot:run
in the root of the code sample to get the app running. -
Using Azure Service Bus Explorer to send a message to the receiving queue.
-
Verify in your app’s logs that 3 similar message was posted:
New message received: 'xxxx' Message 'xxxx' successfully checkpointed Message was sent successfully.
-
Check your another Service Bus queue to see that the above message should be forwarded to it.
If you update the spring.cloud.azure.managed-identity.client-id
property after deploying the app, or update the role assignment for
services, please try to redeploy the app again.
You can follow Deploy a Spring Boot JAR file to Azure App Service to deploy this application to App Service