Created
November 12, 2018 13:03
-
-
Save ealsur/8db229a9d20b37bd4ba41aae033b8fe8 to your computer and use it in GitHub Desktop.
Azure Cosmos DB + Functions Cookbook - Multi master & preferred region
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<HttpResponseMessage> Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, | |
[CosmosDB(databaseName: "%CosmosDBDatabase%", | |
collectionName: "%CosmosDBCollection%", | |
ConnectionStringSetting = "CosmosDBConnectionString", | |
UseMultipleWriteLocations = true, | |
PreferredLocations = "Central US" | |
)] IAsyncCollector<MyClass> documentsToSave, | |
ILogger log) | |
{ | |
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | |
MyClass[] inputDocuments = JsonConvert.DeserializeObject<MyClass[]>(requestBody); | |
if (inputDocuments == null) | |
{ | |
return new HttpResponseMessage(HttpStatusCode.BadRequest); | |
} | |
foreach (MyClass inputDocument in inputDocuments) | |
{ | |
await documentsToSave.AddAsync(inputDocument); | |
log.LogInformation(inputDocument.id); | |
} | |
return new HttpResponseMessage(HttpStatusCode.Created); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment