Created
August 13, 2018 23:02
-
-
Save dbarkol/3d6c36f311525f175854d226ba1cb5e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <send-one-way-request mode="new"> | |
| <set-url>{{event-grid-topic-endpoint}}</set-url> | |
| <set-method>POST</set-method> | |
| <set-header name="aeg-sas-key" exists-action="override"> | |
| <value>{{event-grid-topic-key}}</value> | |
| </set-header> | |
| <set-header name="Content-Type" exists-action="override"> | |
| <value>application/json</value> | |
| </set-header> | |
| <set-body>@{ | |
| // Parse the request body | |
| var requestBody = context.Request.Body.As<string>(); | |
| JObject json = JObject.Parse(requestBody); | |
| // Add the customer ID, order details and | |
| // request ID of the API call to the event | |
| // data property. | |
| var data = json["order"]; | |
| data["customerId"] = json["customerId"]; | |
| data["requestId"] = context.RequestId; | |
| // Set the event type based off of the quantity ordered | |
| var quantity = (int) json["order"]["quantity"]; | |
| var eventType = quantity > 50 ? "Contoso.Orders.Large" : "Contoso.Orders.Normal"; | |
| // Events are sent in an array | |
| var events = new JArray(); | |
| // Initialize the event and add it to the array | |
| var newOrderEvent = new JObject(); | |
| newOrderEvent.Add("Data", data); | |
| newOrderEvent.Add("Subject", "contoso/newOrder"); | |
| newOrderEvent.Add("EventType", eventType); | |
| newOrderEvent.Add("Id", Guid.NewGuid().ToString()); | |
| newOrderEvent.Add("EventTime", DateTime.UtcNow.ToString()); | |
| events.Add(newOrderEvent); | |
| // Format to a string and ready to go! | |
| return events.ToString(Newtonsoft.Json.Formatting.None); | |
| }</set-body> | |
| </send-one-way-request> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment