Skip to content

Commit 452ad61

Browse files
Add 'consistencyLevel' to CosmosDB provider. (#79)
1 parent 0c5a18c commit 452ad61

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ The specific settings available for the new session state module and providers a
4949
* The Sql provider's `UseInMemoryTable` is deprecated. It will continue to be respected in the absence of `RepositoryType`, but is overridden by that setting if given.
5050
* Sql provider `SessionTableName` - A new setting that allows users to target a specific table in their database rather than being forced to use the default table names.
5151
* CosmosDB `collectionId` is now `containerId` in keeping with the updated terminology from the CosmosDB offering. Please use the updated parameter name when configuring your provider. (The old name will continue to work just the same.)
52+
* Added CosmosDB `consistencyLevel` to allow using a different [Consistency Level](https://learn.microsoft.com/en-us/azure/cosmos-db/consistency-levels) with the CosmosClient.
5253
* CosmosDB `connectionProtocol` is obsolete. It will not cause errors to have it in configuration, but it is ignored. The current [CosmosDB SDK chooses the protocol based on connection mode](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-connection-modes).

docs/CosmosDBSessionStateProviderAsync.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Then, register your new provider like so:
99
<providers>
1010
<add name="CosmosDBSessionStateProviderAsync" cosmosDBEndPointSettingKey="cosmosDBEndPointSetting" cosmosDBAuthKeySettingKey="cosmosDBAuthKeySetting"
1111
databaseId="[DataBaseId]" collectionId="[CollectionId]" offerThroughput="5000" connectionMode="Direct" requestTimeout="5"
12-
maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations=""
12+
maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" consistencyLevel="Session" preferredLocations=""
1313
type="Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Microsoft.AspNet.SessionState.CosmosDBSessionStateProviderAsync, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
1414
</providers>
1515
</sessionState>
@@ -34,4 +34,6 @@ Then, register your new provider like so:
3434

3535
8. *maxRetryWaitTimeInSeconds* - The maximum retry time in seconds for the Azure DocumentDB database service.
3636

37-
9. *preferredLocations* - Sets the preferred locations(regions) for geo-replicated database accounts in the Azure DocumentDB database service. Use ';' to split multiple locations. e.g. "East US;South Central US;North Europe"
37+
9. *consistencyLevel* - The [Consistency Level](https://learn.microsoft.com/en-us/azure/cosmos-db/consistency-levels) to use with the CosmosClient. Default is the Cosmos SDK default, which is currently 'Session'.
38+
39+
10. *preferredLocations* - Sets the preferred locations(regions) for geo-replicated database accounts in the Azure DocumentDB database service. Use ';' to split multiple locations. e.g. "East US;South Central US;North Europe"

src/CosmosDBSessionStateProviderAsync/CosmosDBSessionStateProviderAsync.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@ internal static CosmosClientOptions ParseCosmosDBClientSettings(NameValueCollect
854854
MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds(maxRetryWaitTimeInSeconds)
855855
};
856856

857+
if (Enum.TryParse<ConsistencyLevel>(config["consistencyLevel"], out ConsistencyLevel consistencyLevel))
858+
{
859+
clientOptions.ConsistencyLevel = consistencyLevel;
860+
}
861+
857862
var preferredLocations = config["preferredLocations"];
858863
if (!string.IsNullOrEmpty(preferredLocations))
859864
{

src/packages/CosmosDBSessionStateProviderAsync.nupkg/content/Net462/web.config.install.xdt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
maxConnectionLimit: maximum number of concurrent connections allowed for the target service endpoint in the Azure DocumentDB database service.
3030
maxRetryAttemptsOnThrottledRequests: the maximum number of retries in the case where the request fails because the Azure DocumentDB database service has applied rate limiting on the client.
3131
maxRetryWaitTimeInSeconds: the maximum retry time in seconds for the Azure DocumentDB database service.
32+
consistencyLevel: The 'ConsistencyLevel' to use with the CosmosClient. Default is not-specified, leaving the choice to Cosmos SDK. (The current SDK default is 'Session'.)
3233
preferredLocations: sets the preferred locations(regions) for geo-replicated database accounts in the Azure DocumentDB database service. Use ';' to split multiple locations. e.g. "East US;South Central US;North Europe"
33-
partitionKey: the partition key name of the collection
34-
partitionNumUsedByProvider: the number of partition can be used for sessionstate
3534
-->
3635
<add name="CosmosDBSessionStateProviderAsync" cosmosDBEndPointSettingKey="cosmosDBEndPointSetting" cosmosDBAuthKeySettingKey="cosmosDBAuthKeySetting" databaseId="[DataBaseId]" containerId="[ContainerId]" offerThroughput="5000"
3736
connectionMode="Direct" requestTimeout="5" maxConnectionLimit="50" maxRetryAttemptsOnThrottledRequests="10" maxRetryWaitTimeInSeconds="10" preferredLocations=""

0 commit comments

Comments
 (0)