Quest for serverless WebSockets - an adventure ...

Quest for serverless WebSockets - an adventure with Azure Functions and Durable Functions

Session for dotnetdays Romania at 22 Oct 2022.
GitHub repo: https://github.com/ably-labs/serverless-websockets-quest

Marc Duiker

October 22, 2022

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

38 slides
  1. @MarcDuiker 19 public class Counter : ICounter { [JsonProperty("value")] public

    int CurrentValue { get; set; } public void Add(int amount) => this.CurrentValue += amount; public void Reset() => this.CurrentValue = 0; [FunctionName(nameof(Counter))] public static Task Run([EntityTrigger] IDurableEntityContext ctx) => ctx.DispatchAsync<Counter>(); }
  2. @MarcDuiker 20 await _durableClient.SignalEntityAsync<ICounter>( counterEntityId, proxy => proxy.Add(1)); var counter

    = await _durableClient.ReadEntityStateAsync<Counter>( counterEntityId); var current = counter.EntityState.CurrentValue; var counterEntityId = new EntityId(nameof(Counter), counterId); https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-dotnet-entities
  3. @MarcDuiker 24 let webSocket = new WebSocket(”ws://...”); webSocket.onopen = ()

    => { ... }; webSocket.onmessage = (event) => { ... }; webSocket.send(...);
  4. @MarcDuiker 25 var ablyClient = new AblyRealtime(ABLY_API_KEY); var channel =

    ablyClient.Channels.Get(CHANNEL_NAME); channel.Subscribe(“chat-message”, message => { ... }); await channel.PublishAsync( “chat-message", new { user = "Marc“, message = "Hi there!" }); ablyClient.Connection.On(ConnectionEvent.Connected, args => { ... });
  5. @MarcDuiker 29 Client Function App Monster (Player Entity) GameState (Entity)

    GameEngine Ably Signal InitGameState Signal AddPlayerName Publish UpdatePhase Publish AddPlayer CreateQuest Signal InitPlayer CreateQuest

More Decks by Marc Duiker

Other Decks in Programming