I have an API deployed in two regions, and the API has a Cosmos Db resource as data storage.
Cosmos Db is configured with multi-region writes, and I'm trying to redirect the API calls to the closest region.
Before moving to SDK v3, I had this implemented in V2 and it worked like a charm.
With v3 it should work similarly with specifying the client option ApplicationRegion, but it seems not acknowledged when I look at the metrics.
All traffic is handled by my primary region, and not by the closest write region.
I use the code below to configure this in my startup.cs.
The reason I have the 'if' statement with 'cdbPreferredLocation' is read from the config and is because I test locally with CosmosDb emulator and that doesn't (seem to) support the ApplicationRegion setting.
Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(cdbEndpoint, cdbAuthkey, new Microsoft.Azure.Cosmos.CosmosClientOptions
{
SerializerOptions = new Microsoft.Azure.Cosmos.CosmosSerializationOptions
{
IgnoreNullValues = true,
PropertyNamingPolicy = Microsoft.Azure.Cosmos.CosmosPropertyNamingPolicy.CamelCase
}
});
if (!string.IsNullOrWhiteSpace(cdbPreferredLocation))
client.ClientOptions.ApplicationRegion = cdbPreferredLocation;
var service = new CosmosDbService(client, cdbDbName, cdbContainerName);
What am I doing wrong?