-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
575 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
sdk/cosmos/azure-spring-data-cosmos/src/samples/java/com/azure/cosmos/AppConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.cosmos; | ||
/** | ||
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS | ||
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING | ||
* LINE NUMBERS OF EXISTING CODE SAMPLES. | ||
*/ | ||
import com.azure.data.cosmos.CosmosKeyCredential; | ||
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration; | ||
import com.azure.spring.data.cosmos.config.CosmosDBConfig; | ||
import com.azure.spring.data.cosmos.core.ResponseDiagnostics; | ||
import com.azure.spring.data.cosmos.core.ResponseDiagnosticsProcessor; | ||
import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import io.micrometer.core.lang.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Configuration | ||
@EnableCosmosRepositories | ||
public class AppConfiguration extends AbstractCosmosConfiguration { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AppConfiguration.class); | ||
|
||
@Value("${azure.cosmosdb.uri}") | ||
private String uri; | ||
|
||
@Value("${azure.cosmosdb.key}") | ||
private String key; | ||
|
||
@Value("${azure.cosmosdb.secondaryKey}") | ||
private String secondaryKey; | ||
|
||
@Value("${azure.cosmosdb.database}") | ||
private String dbName; | ||
|
||
@Value("${azure.cosmosdb.populateQueryMetrics}") | ||
private boolean populateQueryMetrics; | ||
|
||
private CosmosKeyCredential cosmosKeyCredential; | ||
|
||
public CosmosDBConfig getConfig() { | ||
this.cosmosKeyCredential = new CosmosKeyCredential(key); | ||
CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, | ||
this.cosmosKeyCredential, dbName).build(); | ||
cosmosdbConfig.setPopulateQueryMetrics(populateQueryMetrics); | ||
cosmosdbConfig.setResponseDiagnosticsProcessor(new ResponseDiagnosticsProcessorImplementation()); | ||
return cosmosdbConfig; | ||
} | ||
|
||
public void switchToSecondaryKey() { | ||
this.cosmosKeyCredential.key(secondaryKey); | ||
} | ||
|
||
private static class ResponseDiagnosticsProcessorImplementation implements ResponseDiagnosticsProcessor { | ||
|
||
@Override | ||
public void processResponseDiagnostics(@Nullable ResponseDiagnostics responseDiagnostics) { | ||
logger.info("Response Diagnostics {}", responseDiagnostics); | ||
} | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...ure-spring-data-cosmos/src/samples/java/com/azure/cosmos/AppConfigurationCodeSnippet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.cosmos; | ||
|
||
/** | ||
* WARNING: MODIFYING THIS FILE WILL REQUIRE CORRESPONDING UPDATES TO README.md FILE. LINE NUMBERS | ||
* ARE USED TO EXTRACT APPROPRIATE CODE SEGMENTS FROM THIS FILE. ADD NEW CODE AT THE BOTTOM TO AVOID CHANGING | ||
* LINE NUMBERS OF EXISTING CODE SAMPLES. | ||
*/ | ||
|
||
import com.azure.data.cosmos.ConnectionMode; | ||
import com.azure.data.cosmos.CosmosKeyCredential; | ||
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration; | ||
import com.azure.spring.data.cosmos.config.CosmosDBConfig; | ||
import com.azure.spring.data.cosmos.repository.config.EnableCosmosRepositories; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableCosmosRepositories | ||
public class AppConfigurationCodeSnippet extends AbstractCosmosConfiguration { | ||
// configuration code | ||
@Value("${azure.cosmosdb.uri}") | ||
private String uri; | ||
|
||
@Value("${azure.cosmosdb.key}") | ||
private String key; | ||
|
||
@Value("${azure.cosmosdb.secondaryKey}") | ||
private String secondaryKey; | ||
|
||
@Value("${azure.cosmosdb.database}") | ||
private String dbName; | ||
|
||
@Value("${azure.cosmosdb.populateQueryMetrics}") | ||
private boolean populateQueryMetrics; | ||
|
||
private CosmosKeyCredential cosmosKeyCredential; | ||
|
||
public CosmosDBConfig getConfig() { | ||
this.cosmosKeyCredential = new CosmosKeyCredential(key); | ||
CosmosDBConfig cosmosDbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName).build(); | ||
cosmosDbConfig.getConnectionPolicy().connectionMode(ConnectionMode.DIRECT); | ||
cosmosDbConfig.getConnectionPolicy().maxPoolSize(1000); | ||
return cosmosDbConfig; | ||
} | ||
} |
Oops, something went wrong.