Slide 1

Slide 1 text

SignalR Deep Dive: Building Servers David Fowler – ASP.NET & Azure SignalR Architect @davidfowl Damian Edwards – ASP.NET Program Manager @damianedwards

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Demo: SignalR app

Slide 4

Slide 4 text

Supporting multiple clients • SignalR supports different client types • HTTP transports • WebSockets • ServerSentEvents • Long Polling • Client SDKs • JavaScript • .NET • Java • Swift • Python • C++ (coming soon)

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Transports: Long polling Request Response Request Event Client Server

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Transports: WebSockets upgrade: websocket Client Server messages HTTP/1.1 101 Switching Protocols

Slide 9

Slide 9 text

Negotiate request REQUEST: POST /negotiate[?negotiateVersion=] RESPONSE: { "connectionToken":"05265228-1e2c-46c5-82a1-6a5bcc3f0143", "connectionId":"807809a5-31bf-470d-9e23-afaee35d8a0d", "negotiateVersion":1, "availableTransports":[{ "transport": "WebSockets", "transferFormats": [ "Text", "Binary" ] }] }

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Demo: Build a server… in Go

Slide 12

Slide 12 text

Further considerations • Thread safety • Error handling • Groups • Client-to-server streaming • Cancellation • Frame inter-leaving

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Scale-out • https://docs.microsoft.com/en-us/aspnet/core/signalr/scale

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Business Logic (Hub) Client Pages Web traffic SignalR traffic

Slide 17

Slide 17 text

Business Logic (Hub) Pages Client Endpoint Server Endpoint SignalR traffic Web traffic

Slide 18

Slide 18 text

Client Endpoint Server Endpoint Connection multiplexing clients

Slide 19

Slide 19 text

Function Client Endpoint REST Endpoint BLOB Serverless

Slide 20

Slide 20 text

Demo: Build a SignalR service

Slide 21

Slide 21 text

Questions @davidfowl @damianedwards