ealsur / ondotnet-cosmosdb

Cosmos DB content for OnDotNet on Channel9
https://channel9.msdn.com/Shows/On-NET
MIT License
16 stars 5 forks source link

Is StreamApi really faking it? #3

Closed ali-asghar5 closed 2 months ago

ali-asghar5 commented 2 months ago

Hi mate, Thanks for the sample/ demo and tutorial.

If I use Is Stream APIs, it resulted as completed successfully but no data appear at database. If I switch it with CreateItemAsync then it works but I get Exception 429.

Have I missed anything...

Cheers

ealsur commented 2 months ago

@ali-asghar5

as completed successfully

Are you checking the ResponseMessage StatusCode? Or the ResponseMessage.IsSuccessStatusCode?

A 429 with the Stream APIs will still return a ResponseMessage (there are no exceptions, that's the whole point). You need to inspect the result.

ali-asghar5 commented 2 months ago

image

Above is what I get

ealsur commented 2 months ago

Right, that is not a success. The StatusCode is HTTP 400 (Bad Request). The Stream API is working as expected.

image

Stream APIs won't throw exceptions, it will return the raw response, your code should check if the response is a success or not if you have logic that depends on it.

Just like when you use the Typed-APIs, you try/catch and handle exceptions if that layer needs to.

ali-asghar5 commented 2 months ago

Ah got it. How can I investigate BadRequest, response doesn't carry any message. I can successfully create items using CreateItemAsync just not with CreateItemStreamAsync using the same partition key.

ali-asghar5 commented 2 months ago

Found the issue, I setting CosmosPropertyNamingPolicy.CamelCase for cosmos client SerializerOptions.

https://stackoverflow.com/questions/63799147/how-to-bulk-insert-in-cosmos-db-with-net-core-2-1-and-stream-api