| page_type | sample | |
|---|---|---|
| languages |
|
|
| products |
|
|
| description | Azure Spring Boot Sample project for Cosmos Multi Database Multi Account | |
| urlFragment | azure-spring-boot-sample-cosmos-multi-database-multi-account |
-
Log into https://portal.azure.com.
-
Click
Create a resource. -
Input
Azure Cosmos DB. -
Click Create.
-
On the Create key vault page, input
Subscription,Resource group,Account Name, then clickReview + Create. -
When complete, click
Go to resource. -
Click Keys in the left navigation pane, copy your URI, the PRIMARY KEY and SECONDARY KEY;
-
Replace the content in
application.propertieswith the obtained information. -
We need to create another cosmos DB as the secondary like the steps above.
-
Add MYSQL connection attributes in
application.properties.
# primary account cosmos config
azure.cosmos.primary.uri=your-primary-cosmosDb-uri
azure.cosmos.primary.key=your-primary-cosmosDb-key
azure.cosmos.primary.secondary-key=your-primary-cosmosDb-secondary-key
azure.cosmos.primary.database=your-primary-cosmosDb-dbName
azure.cosmos.primary.populate-query-metrics=if-populate-query-metrics
# secondary account cosmos config
azure.cosmos.secondary.uri=your-secondary-cosmosDb-uri
azure.cosmos.secondary.key=your-secondary-cosmosDb-key
azure.cosmos.secondary.secondary-key=your-secondary-cosmosDb-secondary-key
azure.cosmos.secondary.database=your-secondary-cosmosDb-dbName
azure.cosmos.secondary.populate-query-metrics=if-populate-query-metrics
#mysql connection attributes
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=your-mysql-username
spring.datasource.password=your-mysql-passwordcd azure-spring-boot-samples/azure-spring-boot-sample-multi-database
mvn spring-boot:runVerify Result:
The corresponding data is added to the mysql database and cosmos database







