Skip to content

Commit 1a32511

Browse files
committed
support spring3
1 parent 7f7be97 commit 1a32511

27 files changed

+971
-3
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/spring2sample</module>
109109
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder</module>
110110
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder-arm</module>
111-
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces</module>
111+
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/spring2sample</module>
112112
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace</module>
113113
<module>servicebus/spring-messaging-azure-servicebus/servicebus-spring-messaging</module>
114114
<module>storage/spring-cloud-azure-starter-storage-blob/storage-blob-sample</module>
@@ -179,7 +179,7 @@
179179
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/spring3sample</module>
180180
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder</module>
181181
<module>servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder-arm</module>
182-
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces</module>
182+
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/spring3sample</module>
183183
<module>servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace</module>
184184
<module>servicebus/spring-messaging-azure-servicebus/servicebus-spring-messaging</module>
185185
<module>storage/spring-cloud-azure-starter-storage-blob/storage-blob-sample</module>

servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/pom.xml renamed to servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/spring2sample/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<groupId>com.azure.spring</groupId>
99
<artifactId>azure-spring-boot-samples</artifactId>
1010
<version>1.0.0</version>
11-
<relativePath>../../../pom.xml</relativePath>
11+
<relativePath>../../../../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>spring-cloud-azure-starter-integration-sample-servicebus-multiple-namespaces</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
package com.azure.spring.sample.servicebus;
24

35
import com.azure.spring.integration.core.handler.DefaultMessageHandler;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
package com.azure.spring.sample.servicebus;
24

35
import com.azure.spring.messaging.servicebus.core.DefaultServiceBusNamespaceProcessorFactory;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- java
5+
products:
6+
- azure-service-bus
7+
name: Sending and Receiving Message by Azure Service Bus (Multiple Namespaces) And Spring Integration in Spring Boot Application
8+
description: This sample demonstrates how to send and receive message by Azure Service Bus (multiple namespaces) and Spring Integration in Spring Boot application.
9+
---
10+
11+
# Sending and Receiving Message by Azure Service Bus (Multiple Namespaces) And Spring Integration in Spring Boot Application
12+
13+
This code sample demonstrates how to use Spring Integration to interact with multiple Azure Service Bus namespaces.
14+
15+
## What You Will Build
16+
17+
You will build an application that using Spring Integration for Azure Service Bus to send and receive messages with two Service Bus namespaces.
18+
This sample will send messages to two queues in two different Azure Service Bus namespaces and then receive the messages.
19+
In addition, this sample will forward all messages received from the first queue to the second queue.
20+
21+
## What You Need
22+
23+
- [An Azure subscription](https://azure.microsoft.com/free/)
24+
- [Terraform](https://www.terraform.io/)
25+
- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli)
26+
- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later
27+
- Maven
28+
- You can also import the code straight into your IDE:
29+
- [IntelliJ IDEA](https://www.jetbrains.com/idea/download)
30+
31+
## Provision Azure Resources Required to Run This Sample
32+
This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to:
33+
> [!IMPORTANT]
34+
> If you choose to use a security principal to authenticate and authorize with Microsoft Entra ID for accessing an Azure resource
35+
> please refer to [Authorize access with Microsoft Entra ID](https://learn.microsoft.com/azure/developer/java/spring-framework/authentication#authorize-access-with-microsoft-entra-id) to make sure the security principal has been granted the sufficient permission to access the Azure resource.
36+
37+
### Authenticate Using the Azure CLI
38+
Terraform must authenticate to Azure to create infrastructure.
39+
40+
In your terminal, use the Azure CLI tool to setup your account permissions locally.
41+
42+
```shell
43+
az login
44+
```
45+
46+
Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use.
47+
48+
```shell
49+
You have logged in. Now let us find all the subscriptions to which you have access...
50+
51+
[
52+
{
53+
"cloudName": "AzureCloud",
54+
"homeTenantId": "home-Tenant-Id",
55+
"id": "subscription-id",
56+
"isDefault": true,
57+
"managedByTenants": [],
58+
"name": "Subscription-Name",
59+
"state": "Enabled",
60+
"tenantId": "0envbwi39-TenantId",
61+
"user": {
62+
"name": "[email protected]",
63+
"type": "user"
64+
}
65+
}
66+
]
67+
```
68+
69+
If you have more than one subscription, specify the subscription-id you want to use with command below:
70+
```shell
71+
az account set --subscription <your-subscription-id>
72+
```
73+
74+
### Provision the Resources
75+
76+
After login Azure CLI with your account, now you can use the terraform script to create Azure Resources.
77+
78+
#### Run with Bash
79+
80+
```shell
81+
82+
# in the root directory of the sample
83+
# Initialize your Terraform configuration
84+
terraform -chdir=./terraform init
85+
86+
# Apply your Terraform Configuration
87+
terraform -chdir=./terraform apply -auto-approve
88+
89+
```
90+
91+
#### Run with Powershell
92+
93+
```shell
94+
# In the root directory of the sample
95+
# Initialize your Terraform configuration
96+
terraform -chdir=terraform init
97+
98+
# Apply your Terraform Configuration
99+
terraform -chdir=terraform apply -auto-approve
100+
101+
```
102+
103+
It may take a few minutes to run the script. After successful running, you will see prompt information like below:
104+
105+
```shell
106+
107+
...
108+
azurerm_role_assignment.servicebus_02_data_owner: Still creating...
109+
azurerm_role_assignment.servicebus_01_data_owner: Still creating...
110+
azurerm_role_assignment.servicebus_01_data_owner: Creation complete after 29s...
111+
azurerm_role_assignment.servicebus_02_data_owner: Creation complete after 29s...
112+
113+
Apply complete! Resources: 14 added, 0 changed, 0 destroyed.
114+
115+
Outputs:
116+
117+
AZURE_SERVICEBUS_NAMESPACE_01 = "${YOUR_SERVICEBUS_NAMESPACE_01}"
118+
AZURE_SERVICEBUS_NAMESPACE_02 = "${YOUR_SERVICEBUS_NAMESPACE_02}"
119+
AZURE_SERVICEBUS_NAMESPACE_01_QUEUE_NAME = "${YOUR_AZURE_SERVICEBUS_NAMESPACE_01_QUEUE_NAME}"
120+
AZURE_SERVICEBUS_NAMESPACE_02_QUEUE_NAME = "${YOUR_AZURE_SERVICEBUS_NAMESPACE_02_QUEUE_NAME}"
121+
```
122+
123+
You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created.
124+
125+
### Export Output to Your Local Environment
126+
Running the command below to export environment values:
127+
128+
#### Run with Bash
129+
130+
```shell
131+
source ./terraform/setup_env.sh
132+
```
133+
134+
#### Run with Powershell
135+
136+
```shell
137+
terraform\setup_env.ps1
138+
```
139+
140+
If you want to run the sample in debug mode, you can save the output value.
141+
142+
```shell
143+
AZURE_SERVICEBUS_NAMESPACE_01=...
144+
AZURE_SERVICEBUS_NAMESPACE_02=...
145+
AZURE_SERVICEBUS_NAMESPACE_01_QUEUE_NAME=...
146+
AZURE_SERVICEBUS_NAMESPACE_02_QUEUE_NAME=...
147+
```
148+
149+
## Run Locally
150+
151+
### Run the sample with Maven
152+
153+
In your terminal, run `mvn clean spring-boot:run`.
154+
155+
```shell
156+
mvn clean spring-boot:run
157+
```
158+
159+
### Run the sample in IDEs
160+
161+
You can debug your sample by adding the saved output values to the tool's environment variables or the sample's `application.yaml` file.
162+
163+
* If your tool is `IDEA`, please refer to [Debug your first Java application](https://www.jetbrains.com/help/idea/debugging-your-first-java-application.html) and [add environment variables](https://www.jetbrains.com/help/objc/add-environment-variables-and-program-arguments.html#add-environment-variables).
164+
165+
* If your tool is `ECLIPSE`, please refer to [Debugging the Eclipse IDE for Java Developers](https://www.eclipse.org/community/eclipse_newsletter/2017/june/article1.php) and [Eclipse Environment Variable Setup](https://examples.javacodegeeks.com/desktop-java/ide/eclipse/eclipse-environment-variable-setup-example/).
166+
167+
## Verify This Sample
168+
169+
170+
Verify in your app’s logs that similar messages were posted:
171+
```shell
172+
Receive messages from the first queue: 1
173+
Receive messages from the second queue: 2
174+
...
175+
Receive messages from the second queue: transformed from queue1, 1
176+
...
177+
```
178+
179+
180+
## Clean Up Resources
181+
After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing.
182+
183+
The terraform destroy command terminates resources managed by your Terraform project.
184+
To destroy the resources you created.
185+
186+
#### Run with Bash
187+
188+
```shell
189+
terraform -chdir=./terraform destroy -auto-approve
190+
```
191+
192+
#### Run with Powershell
193+
194+
```shell
195+
terraform -chdir=terraform destroy -auto-approve
196+
```
197+
198+
## Deploy to Azure Spring Apps
199+
200+
Now that you have the Spring Boot application running locally, it's time to move it to production. [Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/overview) makes it easy to deploy Spring Boot applications to Azure without any code changes. The service manages the infrastructure of Spring applications so developers can focus on their code. Azure Spring Apps provides lifecycle management using comprehensive monitoring and diagnostics, configuration management, service discovery, CI/CD integration, blue-green deployments, and more. To deploy your application to Azure Spring Apps, see [Deploy your first application to Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/quickstart?tabs=Azure-CLI).

0 commit comments

Comments
 (0)