Skip to content

Instantly share code, notes, and snippets.

View jeffhollan's full-sized avatar
❄️
Working

Jeff Hollan jeffhollan

❄️
Working
View GitHub Profile
public class BloggingContextFactory : IDesignTimeDbContextFactory<BloggingContext>
{
public BloggingContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();
optionsBuilder.UseSqlServer(Environment.GetEnvironmentVariable("SqlConnectionString"));
return new BloggingContext(optionsBuilder.Options);
}
}
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
[assembly: FunctionsStartup(typeof(functions_csharp_entityframeworkcore.Startup))]
namespace functions_csharp_entityframeworkcore
{
class Startup : FunctionsStartup
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;
namespace functions_csharp_entityframeworkcore
{
public class HttpTrigger
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
namespace functions_csharp_entityframeworkcore
{
public class BloggingContext : DbContext
{
public BloggingContext(DbContextOptions<BloggingContext> options)
@jeffhollan
jeffhollan / topicRetry.md
Last active April 9, 2019 14:17
Topic exponential retry

What about topics?

Topics are tricky because it's a pub/sub model. If you publish one message to the topic, all subscribers receive a copy of that message. Let's say I have a topic with 10 subscribers. Subscriber 1-9 process the message just fine. Subscriber 10 gets its message, but hits an exception. If you followed this code above for the topic, the message would be scheduled back onto the topic. However, that means not only would subscriber 10 get the retry, but subscribers 1-9 would get a copy of the retry too.

My recommendation is that for topics where you want to enable exponential retries, use the forwarding feature of Azure Service Bus. The forwarding feature allows you to forward all messages to a queue or topic subscription to another queue or topic. In the case above I created a queue in my namespace for subscriber 10. I then ran the following CLI command to forward all messages to subscriber 10s subscription to that new queue. Now I have my function fire and exponentially retry on t

@jeffhollan
jeffhollan / GameSessionActor.cs
Last active April 9, 2019 15:08
Tic Tac Toe durable sample
using System;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
namespace DurableFunctionsAlpha.TicTacToe
{
public static class GameSessionActor
{
[FunctionName("GameSessionActor")]
public static async Task RunGame(
@jeffhollan
jeffhollan / GitHubWebookFunction.cs
Last active April 7, 2019 23:57
Brainstorming around how actor interface could be exposed for csharp
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 DurableFunctionsAlpha.BlueSky;
namespace DurableFunctionsAlpha
{
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
;SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetKeyDelay, 10
^+1::
Send, ["value"]
Return
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"SuperSecret": "I love Azure Functions",
"EventHubConnectionString": "Endpoint=sb://jeffs.servicebus.windows.net/;SharedAccessKeyName=MyFakeKey;SharedAccessKey=NotARealSecret"
}
}
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace KeyVault
{
public static class MyFunctionClass
{
private static string superSecret = System.Environment.GetEnvironmentVariable("SuperSecret");