1
votes

I am using Cosmos DB multi-region (single region write) account. Currently it is enabled in East US and West US. The write region is West US. The change feed listeners are deployed in both East US and West US.

Given this setup, I wanted to understand, how does the change feed work?

  1. Do the change feed listeners receive change feed from the region where they are deployed. Example - Listeners in East reads from East and listeners in West read from West.

OR

  1. They read from the write region. West US in my case.

I am using change feed processor library to read change feed and the code is:

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;
1

1 Answers

0
votes

By default, changes will be read from the Write region (West US). If you want changes to be read from another region, you can simply use the ConnectionPolicy setting in DocumentCollectionInfo like so:

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
};