Skip to content

Commit c020419

Browse files
add sample for multi datasource (Azure#19655)
1 parent cafe870 commit c020419

File tree

48 files changed

+1057
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1057
-318
lines changed

sdk/cosmos/azure-spring-data-cosmos/README.md

Lines changed: 188 additions & 65 deletions
Large diffs are not rendered by default.

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/multidatasource/MultiDatasourceApplication.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/multidatasource/PrimaryDatasourceConfiguration.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/multidatasource/primary/database1/UserRepository.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/multidatasource/secondary/database3/Book.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/spring/data/cosmos/multidatasource/secondary/database3/BookRepository.java

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Azure Spring Boot Sample Cosmos Multi Database Multi Account for Java
2+
3+
## Key concepts
4+
## Getting started
5+
6+
### Environment checklist
7+
We need to ensure that this [environment checklist][ready-to-run-checklist] is completed before the run.
8+
9+
### Configure Cosmos Database
10+
1. Log into <https://portal.azure.com>.
11+
12+
1. Click `Create a resource`.
13+
14+
1. Input `Azure Cosmos DB`.
15+
16+
1. Click `Azure Cosmos DB`
17+
![Find Cosmos Resource 01](resource/creating-cosmos-01.png)
18+
19+
![Find Cosmos Resource 02](resource/creating-cosmos-02.png)
20+
21+
1. Click **Create**.
22+
23+
![Create new Cosmos](resource/creating-cosmos-03.png)
24+
25+
1. On the **Create key vault** page, input `Subscription`, `Resource group`, `Account Name`, then click `Review + Create`.
26+
27+
![Specify the options](resource/specify-the-options.png)
28+
29+
![Create Cosmos resource](resource/create-cosmos-resource.png)
30+
31+
1. When complete, click `Go to resource`.
32+
33+
![Go to resource](resource/go-to-resource.png)
34+
35+
1. Click **Keys** in the left navigation pane, copy your **URI**, the **PRIMARY KEY** and **SECONDARY KEY**;
36+
37+
![Get Connect Info](resource/get-connect-info.png)
38+
39+
1. Replace the content in `application.properties` with the obtained information.
40+
41+
1. We need to create another cosmos DB as the secondary like the steps above.
42+
43+
1. Add MYSQL connection attributes in `application.properties`.
44+
45+
## Key concepts
46+
## Examples
47+
### Configure application.yml
48+
```yaml
49+
# primary account cosmos config
50+
azure.cosmos.primary.uri=your-primary-cosmosDb-uri
51+
azure.cosmos.primary.key=your-primary-cosmosDb-key
52+
azure.cosmos.primary.secondary-key=your-primary-cosmosDb-secondary-key
53+
azure.cosmos.primary.database=your-primary-cosmosDb-dbName
54+
azure.cosmos.primary.populate-query-metrics=if-populate-query-metrics
55+
56+
# secondary account cosmos config
57+
azure.cosmos.secondary.uri=your-secondary-cosmosDb-uri
58+
azure.cosmos.secondary.key=your-secondary-cosmosDb-key
59+
azure.cosmos.secondary.secondary-key=your-secondary-cosmosDb-secondary-key
60+
azure.cosmos.secondary.database=your-secondary-cosmosDb-dbName
61+
azure.cosmos.secondary.populate-query-metrics=if-populate-query-metrics
62+
63+
#mysql connection attributes
64+
spring.jpa.hibernate.ddl-auto=update
65+
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
66+
spring.datasource.username=your-mysql-username
67+
spring.datasource.password=your-mysql-password
68+
```
69+
70+
### Run with Maven
71+
```shell
72+
cd azure-spring-boot-samples/azure-spring-boot-sample-multi-database
73+
mvn spring-boot:run
74+
```
75+
76+
Verify Result:
77+
The corresponding data is added to the mysql database and cosmos database
78+
![Result in MYSQL](resource/result-in-mysql.png)
79+
![Result in Primary Cosmos Database](resource/result-in-primary-cosmos-database.png)
80+
![Result in Secondary Cosmos Database](resource/result-in-secondary-cosmos-database.png)
81+
82+
## Troubleshooting
83+
## Next steps
84+
## Contributing
85+
86+
<!-- LINKS -->
87+
[ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<groupId>org.springframework.boot</groupId>
6+
<artifactId>spring-boot-starter-parent</artifactId>
7+
<version>2.4.3</version> <!-- {x-version-update;org.springframework.boot:spring-boot-starter-parent;external_dependency} -->
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
11+
<groupId>com.azure.spring</groupId>
12+
<artifactId>azure-spring-boot-sample-cosmos-multi-database-multi-account</artifactId>
13+
<version>1.0.0</version> <!-- {x-version-update;com.azure.spring:azure-spring-boot-sample-cosmos-multi-database;current} -->
14+
<name>azure-spring-boot-sample-cosmos-multi-database</name>
15+
<description>Azure Spring Boot Sample Cosmos Multi Database</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-data-jpa</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>mysql</groupId>
24+
<artifactId>mysql-connector-java</artifactId>
25+
<scope>runtime</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.azure</groupId>
29+
<artifactId>azure-spring-data-cosmos</artifactId>
30+
<version>3.5.0-beta.1</version> <!-- {x-version-update;com.azure:azure-spring-data-cosmos;current} -->
31+
</dependency>
32+
</dependencies>
33+
</project>
Loading
126 KB
Loading

0 commit comments

Comments
 (0)