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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
@dbarkol
dbarkol / outbox-transaction-function-bindings.cs
Last active October 25, 2022 15:46
The trigger and bindings used for the outbox processor function
[FunctionName("OrderOutboxWorker")]
public static async Task Run(
[CosmosDBTrigger(
databaseName: "%CosmosDBDatabaseName%",
collectionName: "%CosmosDBCollectionName%",
ConnectionStringSetting = "CosmosDBConnectionString",
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = "%CosmosDBLeaseCollectionName%")] IReadOnlyList<Document> input,
[CosmosDB(
databaseName: "%CosmosDBDatabaseName%",
@dbarkol
dbarkol / outbox-transaction-function.cs
Created October 24, 2022 22:51
Demonstrates how to insert documents into Cosmos DB with a transactional batch
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 OrderMaker.Models;
@dbarkol
dbarkol / outbox-transaction-startup.cs
Created October 24, 2022 05:13
Outbox pattern - Dependency injection for Cosmos
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[assembly: FunctionsStartup(typeof(OrderMaker.Startup))]
@dbarkol
dbarkol / cloudevent-sample.json
Last active June 18, 2021 21:34
Sample cloud event
{
"specversion" : "1.0",
"id" : "b85d631a-101e-005a-02f2-cee7aa06f148",
"type" : "contoso.loyalty.update",
"source" : "https://contoso.com/loyalty",
"subject" : "contoso/loyalty/points",
"time" : "2021-06-14T10:00:00Z",
"data" : {
"loyaltyId": "100",
"points": "400",
@dbarkol
dbarkol / songrequest-cloudevent.json
Created June 18, 2021 18:08
Song request in cloud event format
{
"specversion" : "1.0",
"id" : "b85d631a-101e-005a-02f2-cee7aa06f148",
"type" : "zohan.music.request",
"source" : "https://zohan.dev/music/",
"subject" : "zohan/music/requests/4322",
"time" : "2020-09-14T10:00:00Z",
"data" : {
"artist": "Gerardo",
"song": "Rico Suave"
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
{
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 February 22, 2021 06:38
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);
}
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),