Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
724 stars 481 forks source link

Populate Headers.Session on FeedResponse from GetChangeFeedIterator (pull model) #4267

Open TravisTroyer opened 6 months ago

TravisTroyer commented 6 months ago

Is your feature request related to a problem? Please describe. I have a change feed consumer that reacts to certain changes by putting a message on a service bus queue to be handled by another process downstream. I don't include the actual document in the service bus queue because the downstream process may not need it, or may need other documents in the same partition to complete its task. That process is designed to work independently, knowing just the partition ID it's working with.

The problem is that we're using session consistency and sometimes the change consumer becomes aware of a new document, but the downstream process doesn't get that document when it reads all the documents out of the partition.

Describe the solution you'd like FeedResponse.Headers.Session exists, but is always null when using GetChangeFeedIterator. I'd like it to not be null.

Describe alternatives you've considered I've considered putting the document in my service bus message, but that comes with some weirdness, as described above. I've also considered retrying downstream if the latest document observed by the change feed consumer isn't in my query results if and when the downstream process attempts to do its work. The latter is what I'm doing now, but having access to the Session token header would really provide a better solution.

Additional context Passing around and using the the session token when making requests is described as a suggested pattern in the CosmosDb documentation, but isn't possible in this scenario because the SDK isn't returning the Session token:

https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-manage-consistency?tabs=portal%2Cdotnetv2%2Capi-async#utilize-session-tokens

Also worth noting, the Session header is available when using the change feed processor, instead of the pull model.

ealsur commented 6 months ago

Duplicate of https://github.com/Azure/azure-cosmos-dotnet-v3/issues/3115