Azure / azure-documentdb-changefeedprocessor-dotnet

This library provides a host for distributing change feed events in partitioned collection across multiple observers. Instances of the host can scale up (by adding) or down (by removing) dynamically, and the load will be automatically distributed among active instances in about-equal way.
Other
51 stars 22 forks source link

Parsing DateTimeOffset #141

Closed ChiefWiggum closed 4 years ago

ChiefWiggum commented 5 years ago

We're using DateTimeOffsets in CosmosDB, but when using the Change Feed Processor library (v2) the dates always get converted. This can be resolved by using a custom DocumentClient that has custom JsonSerializerSettings and then use this client with .WithFeedDocumentClient(docClient) when building it.

var serializerSettings = new JsonSerializerSettings
{
    DateParseHandling = DateParseHandling.DateTimeOffset
};

var docClient  = new DocumentClient(config.Database.Uri, config.Database.Write.Key, serializerSettings);

var builder = new ChangeFeedProcessorBuilder();

_processor = await builder
    .WithFeedDocumentClient(docClient)
    .BuildAsync();

await _processor.StartAsync();

Is this the recommended way of solving the parsing issue?

ealsur commented 4 years ago

This issue is really tied to the V2 SDK, this library does not have any particular logic or code that relies on the SDK behaving one way or the other.

The way you solved the scenario is basically what I would recommend.