Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
poppin and lockin

David Barkol dbarkol

💭
poppin and lockin
View GitHub Profile
View Zohan.SchemaRegistry.Consumer.cs
using Azure.Identity;
using Confluent.Kafka;
using Microsoft.Azure.Kafka.SchemaRegistry.Avro;
using System;
using System.Configuration;
using System.Threading;
using zohan.schemaregistry.events;
namespace Zohan.SchemaRegistry.Consumer
{
View Zohan.SchemaRegistry.Producer.cs
using Azure.Identity;
using Confluent.Kafka;
using Microsoft.Azure.Kafka.SchemaRegistry.Avro;
using System;
using System.Configuration;
using System.Threading.Tasks;
using zohan.schemaregistry.events;
namespace Zohan.SchemaRegistry.Producer
{
@dbarkol
dbarkol / KafkaAvroDeserializer.cs
Last active Feb 22, 2021
KafkaAvroDeserializer.cs
View KafkaAvroDeserializer.cs
public T Deserialize(ReadOnlySpan<byte> data, bool isNull, SerializationContext context)
{
if (data.IsEmpty)
{
return default(T);
}
return (T) this.serializer.Deserialize(new MemoryStream(data.ToArray()), typeof(T), CancellationToken.None);
}
View KafkaAvroAsyncSerializer.cs
public class KafkaAvroAsyncSerializer<T> : IAsyncSerializer<T>
{
private readonly SchemaRegistryAvroObjectSerializer serializer;
public KafkaAvroAsyncSerializer(string schemaRegistryUrl, TokenCredential credential, string schemaGroup, Boolean autoRegisterSchemas = false)
{
this.serializer = new SchemaRegistryAvroObjectSerializer(
new SchemaRegistryClient(
schemaRegistryUrl,
credential),
View schema-registry-app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="EH_FQDN" value="{eventhubs-namespace-name}.servicebus.windows.net:9093"/>
<add key="EH_CONNECTION_STRING" value="Endpoint=sb://{eventhubs-namespace-name}.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxx"/>
<add key="EH_NAME" value="{event-hub-name}"/>
<add key="CA_CERT_LOCATION" value=".\cacert.pem"/>
<add key="SCHEMA_GROUP" value="{schema-group-name}"/>
<add key="SCHEMA_REGISTRY_URL" value="{eventshubs-namespace-name}.servicebus.windows.net"/>
<add key="SCHEMA_REGISTRY_TENANT_ID" value="{tenant id}"/>
View dapr-subscribe-go.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
View dapr-subscribe-csharp.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using CloudNative.CloudEvents;
using SongRequests.Models;
using Newtonsoft.Json;
namespace SongRequests.Controllers
{
View dapr-subscribe-node.js
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json({ type: 'application/*+json' }));
const port = 3000
app.get('/dapr/subscribe', (req, res) => {
res.json([
{
@dbarkol
dbarkol / cloudevents-options-apim.xml
Created Jan 20, 2020
CloudEvents validation with APIM
View cloudevents-options-apim.xml
<inbound>
<base />
<!-- Get the WebHook-Request-Origin -->
<set-variable value="@(context.Request.Headers.GetValueOrDefault("WebHook-Request-Origin"))"
name="webhookRequestOrigin" />
<!--
Return the response with the allowed origin
and allowed rate to confirm the subscription.
@dbarkol
dbarkol / cloudevents-options-functions.cs
Created Jan 20, 2020
CloudEvents validation with Azure Functions
View cloudevents-options-functions.cs
public static class TestFuncApi
{
[FunctionName("TestFuncApi")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", "options", Route = null)] HttpRequest req,
ILogger log)
{
if (req.Method == "OPTIONS")
{
// Retrieve the request origin