我正在使用Cosmos DB多区域(单个区域写入)帐户。目前,在美国东部和美国西部启用了此功能。书写区域是美国西部。变更Feed侦听器已部署在美国东部和美国西部。
鉴于此设置,我想了解更改提要如何工作?
OR
我正在使用更改提要处理器库来读取更改提要,并且代码是:
var feedCollection = new DocumentCollectionInfo()
{
DatabaseName = configurations.CosmosDb.DatabaseId,
CollectionName = configurations.CosmosDb.CollectionId,
Uri = new Uri(configurations.CosmosDb.EndpointUri),
MasterKey = configurations.CosmosDb.AuthKey
};
var leaseCollection = new DocumentCollectionInfo()
{
DatabaseName = configurations.LeaseCollection.DatabaseId,
CollectionName = configurations.LeaseCollection.CollectionId,
Uri = new Uri(configurations.CosmosDb.EndpointUri),
MasterKey = configurations.CosmosDb.AuthKey
};
var builder = new ChangeFeedProcessorBuilder();
var processor = builder
.WithHostName(hostName)
.WithFeedCollection(feedCollection)
.WithLeaseCollection(leaseCollection)
.WithObserverFactory(observerFactory)
.BuildAsync().Result;
答案 0 :(得分:0)
默认情况下,将从“写”区域(美国西部)读取更改。如果您希望从其他区域读取更改,则可以像这样简单地使用ConnectionPolicy
中的DocumentCollectionInfo
设置:
ConnectionPolicy regionalPolicy = new ConnectionPolicy();
regionalPolicy.PreferredLocations.Add("East US");
var feedCollection = new DocumentCollectionInfo()
{
DatabaseName = configurations.CosmosDb.DatabaseId,
CollectionName = configurations.CosmosDb.CollectionId,
Uri = new Uri(configurations.CosmosDb.EndpointUri),
MasterKey = configurations.CosmosDb.AuthKey,
ConnectionPolicy = regionalPolicy
};