Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Quest for Serverless Websockets - .NET Amsterdam

Quest for Serverless Websockets - .NET Amsterdam

Marc Duiker

April 13, 2023
Tweet

More Decks by Marc Duiker

Other Decks in Technology

Transcript

  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