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

SignalR Deep Dive

1fe64ebb176498be5f73ab51986c6b7b?s=47 David Fowler
January 29, 2020

SignalR Deep Dive

You’ve likely already seen that SignalR supports multiple client types, including .NET, JavaScript, and Java. But what about the server side? Could we build a SignalR server in something other than .NET? Go perhaps, or Node.js? If so, what would you learn? Why would you do it? How would you even begin?

In this session, David and Damian from the ASP.NET team will explore what goes into building a SignalR server that can speak to any SignalR client. You’ll come away with a better understanding of exactly how SignalR works, and perhaps even ideas on how to extend SignalR further for your needs.

1fe64ebb176498be5f73ab51986c6b7b?s=128

David Fowler

January 29, 2020
Tweet

Transcript

  1. SignalR Deep Dive: Building Servers David Fowler – ASP.NET &

    Azure SignalR Architect @davidfowl Damian Edwards – ASP.NET Program Manager @damianedwards
  2. What is SignalR? • Framework for duplex RPC & streaming

    between client and server • Provides “real-time” messaging & server-push functionality • Protocols for transport and messaging layers allow broad reach • Server support for client addressing & grouping, e.g.: • Send to all clients • Send to this one client (connection or user) • Send to this group of clients
  3. Demo: SignalR app

  4. Supporting multiple clients • SignalR supports different client types •

    HTTP transports • WebSockets • ServerSentEvents • Long Polling • Client SDKs • JavaScript • .NET • Java • Swift • Python • C++ (coming soon)
  5. How though? • This client flexibility is enabled by two

    protocol layers • Transport protocol provides flexibility for connection types, e.g. HTTP vs. TCP/IP • https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/ TransportProtocols.md • Hub protocol provides flexibility for message formats, e.g. JSON vs. MessagePack • https://github.com/dotnet/aspnetcore/blob/master/src/SignalR/docs/specs/ HubProtocol.md
  6. Transports: Long polling Request Response Request Event Client Server

  7. Transports: Server-sent events new EventSource(…) Message Event Client Server Message

    Event Message Event
  8. Transports: WebSockets upgrade: websocket Client Server messages HTTP/1.1 101 Switching

    Protocols
  9. Negotiate request REQUEST: POST <endpoint-base>/negotiate[?negotiateVersion=<version>] RESPONSE: { "connectionToken":"05265228-1e2c-46c5-82a1-6a5bcc3f0143", "connectionId":"807809a5-31bf-470d-9e23-afaee35d8a0d", "negotiateVersion":1,

    "availableTransports":[{ "transport": "WebSockets", "transferFormats": [ "Text", "Binary" ] }] }
  10. Hub protocol message types Message Name Sender HandshakeRequest Client HandshakeResponse

    Server Close Callee, Caller Invocation Caller StreamInvocation Caller StreamItem Callee, Caller Completion Callee, Caller CancelInvocation Caller Ping Caller, Callee
  11. Demo: Build a server… in Go

  12. Further considerations • Thread safety • Error handling • Groups

    • Client-to-server streaming • Cancellation • Frame inter-leaving
  13. Messaging Transport frames message message message message Hub frames message

    message message message message message header payload WebSocket transport frame { "type": 6 } JSON ping { "type": 1, "target": "Send", "arguments": [ 42, "Test Message" ] } JSON non-blocking invocation
  14. Scale-out • https://docs.microsoft.com/en-us/aspnet/core/signalr/scale

  15. Azure SignalR Service • Provides SignalR scale-out as a service

    • Offloads SignalR connection handling to the service • Relays client traffic to/from your app over few WebSockets • https://github.com/Azure/azure- signalr/blob/dev/specs/ServiceProtocol.md
  16. Business Logic (Hub) Client Pages Web traffic SignalR traffic

  17. Business Logic (Hub) Pages Client Endpoint Server Endpoint SignalR traffic

    Web traffic
  18. Client Endpoint Server Endpoint Connection multiplexing clients

  19. Function Client Endpoint REST Endpoint BLOB Serverless

  20. Demo: Build a SignalR service

  21. Questions @davidfowl @damianedwards