-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathazurefunction.cs
52 lines (47 loc) · 1.99 KB
/
azurefunction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.CosmosDB;
using Microsoft.Azure.ServiceBus;
namespace FunctionApp4
{
public class Product {
public string id { get; set; }
public int quantity { get; set; }
public int Price { get; set; }
public string Location { get; set; }
}
public static class ProductWrite
{
[FunctionName("ProductWrite")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] Product req,
[CosmosDB("Product","ProductWrite",ConnectionStringSetting = "productwrite",Id ="{id}",PartitionKey ="{Location}")] IAsyncCollector<Product> products,
[ServiceBus("ordertopic", Connection = "sbproduct", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)] IAsyncCollector<Product> sbproduct,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
await products.AddAsync(req);
await sbproduct.AddAsync(req);
return (ActionResult)new OkObjectResult($"Your Product has been submitted !!");
}
}
public static class ProductRead
{
[FunctionName("ProductRead")]
public static async Task Run(
[ServiceBusTrigger("ordertopic", "orderreadsub", Connection = "sbproduct")] Product req,
[CosmosDB("Product", "ProductRead", ConnectionStringSetting = "productwrite", Id = "{id}", PartitionKey = "{Location}")] IAsyncCollector<Product> products,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
await products.AddAsync(req);
}
}
}