Skip to content

Instantly share code, notes, and snippets.

View dbarkol's full-sized avatar
💭
poppin and lockin

David Barkol dbarkol

💭
poppin and lockin
View GitHub Profile
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;
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))]
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
using System.Threading.Tasks;
namespace Zohan.KafkaDemo
{
public interface IKafkaProducer
{
Task SendEvent(string topicName, string key, string value);
}
}
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
<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">
// 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;
<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>@{
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};
<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"];