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
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 Confluent.Kafka; |
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
using System; | |
using System.IO; | |
using System.Linq; | |
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
[assembly: FunctionsStartup(typeof(Zohan.KafkaDemo.Startup))] |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Extensions.Logging; | |
using Confluent.Kafka; | |
namespace Zohan.KafkaDemo |
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
using System.Threading.Tasks; | |
namespace Zohan.KafkaDemo | |
{ | |
public interface IKafkaProducer | |
{ | |
Task SendEvent(string topicName, string key, string value); | |
} | |
} |
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
using System; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using Microsoft.Azure.WebJobs; | |
using Microsoft.Extensions.Logging; | |
using System.Collections.Generic; | |
using Models; | |
using Newtonsoft.Json; | |
namespace ForecastProcessor |
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
<policies> | |
<inbound> | |
<base /> | |
<!-- Limit the number of calls from an IP address --> | |
<rate-limit-by-key calls="5" renewal-period="10" counter-key="@(context.Request.IpAddress)" /> | |
<!-- Publish an event to grid --> | |
<send-one-way-request mode="new"> |
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
// 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; |
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
<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>@{ |
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
var obj = JSON.parse(inputData.rawBody); | |
if (inputData.eventType === 'SubscriptionValidation') { | |
fetch(obj[0].data.validationUrl) | |
.then(function(res) { | |
return res.text(); | |
}) | |
.then(function(body) { | |
var output = {eventType: inputData.eventType}; |
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
<when condition="@(context.Variables.GetValueOrDefault<bool>("isEventGridNotification"))"> | |
<send-one-way-request mode="new"> | |
<set-url>https://hooks.slack.com/services/{{slack-key}}</set-url> | |
<set-method>POST</set-method> | |
<set-body>@{ | |
var events = context.Request.Body.As<string>(); | |
JArray a = JArray.Parse(events); | |
var eventGridData = a.First["data"]; | |
var station = eventGridData["station"]; | |
var artist = eventGridData["artist"]; |