Sessione presentata a CodeGen 2018, evento di CloudGenVerona.
SignalR, il WebSocket che tanto ci mancava.
Vengono presentati scenari On-Premise e Cloud scalabili.
8. 8
I creatori
David Fowler Damian Edwards
SignalR nacque nel 2011
Socket.io, release (0.1.0), il 19/03/2010
9. 9
La storia in ASP .NET
Fu portato nel progetto ASP.NET nel 2013.
In quell’anno WebSocket era un protocollo, appena
standardizzato, ma che molti browser non conoscevano.
Si utilizzavano tecnichiche come polling e altre tecniche
come il Server-Side Event non erano ancora
completamente implementate dai browser.
SignalR nacque per risolvere il problema e inserire un
supporto all’interno dello stack ASP .NET. SignalR divenne
una libreria di riferimento per il RealTime.
10. 10
La storia in ASP .NET
SignalR quindi si fa carico di negoziare il miglior
protocollo di trasporto disponibile per la comunicazione.
SignalR, alla nascita, era strettamente accoppiato a jQuery.
Il web di allora lo era quasi interamente.
Altre funzionalità native dello strumento:
• Riconnessione automatica
• Scalabilità chiavi in mano (Service-Bus)
12. 12
La rinascita
Nel 2018 viene interamente riscritto.
Nessuna dipendenza con la libreria jQuery.
Scalabilità (Redis – Azure SignalR Service)
Cross-platform
Estendibile
Disponibile dalla versione ASP .NET Core 2.1
Client: Javascript – Typescript – .NET - Node.js - Python
Prossime release: Java e C++
Planning: Go, PHP
13. 13
I pacchetti disponibili per ASP .NET Signlar
ASP .NET:
https://www.nuget.org/packages/Microsoft.AspNet.SignalR/
JavaScript:
https://www.nuget.org/packages/Microsoft.AspNet.SignalR.JS/
C++: https://github.com/SignalR/SignalR-Client-Cpp
NodeJS: None
PHP: None
Go: None
Python: https://pypi.org/project/signalr-client/
Java: https://github.com/SignalR/java-client
14. 14
I pacchetti disponibili per ASP .NET Core
ASP .NET Core: 'Microsoft.AspNetCore.SignalR.Client' on NuGet
(https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR/)
Java: 'com.microsoft.aspnet:signalr' on Maven
(https://search.maven.org/artifact/com.microsoft.aspnet/signalr)
JavaScript (including NodeJS): '@aspnet/signalr' on NPM
(https://www.npmjs.com/package/@aspnet/signalr)
C++: (Prototype) https://github.com/aspnet/SignalR/tree/master/clients/cpp
(no official release planned yet)
Swift: (Unofficial) SwiftSignalRClient on CocoaPods
(https://github.com/moozzyk/SignalR-Client-Swift)
PHP ?
Go: Planning
Python: Planning
https://github.com/aspnet/SignalR/tree/release/2.2/specs Per contribuire
16. “A transport is required to have
the following attributes:
Duplex
Binary-safe
Text-safe
17. 17
SignalR
A transport is required to have the following attributes:
Duplex
Able to send messages from Server to Client and from Client
to Server
18. 18
SignalR
A transport is required to have the following attributes:
Binary-safe
Able to transmit arbitrary binary data, regardless of content
19. 19
SignalR
A transport is required to have the following attributes:
Text-safe
Able to transmit arbitrary text data, preserving the content.
Line-endings must be preserved but may be converted to a
different format. For example rn may be converted to n.
This is due to quirks in some transports (Server Sent Events). If
the exact line-ending needs to be preserved, the data should
be sent as a Binary message.
20. 20
SignalR
The only transport which fully implements the duplex
requirement is WebSockets
The others are "half-transports" which implement one end of
the duplex connection.
They are used in combination to achieve a duplex connection.
21. 21
SignalR
ASP.NET Core SignalR was built to be a general purpose
RPC(remote procedure call) based communication library.
It supports:
• Multicast
• Broadcast
• Groups
• Bidirectional RPC
• Streaming
27. 27
Web Socket
WebSocket è una tecnologia web che fornisce canali di
comunicazione full-duplex attraverso una singola
connessione TCP. L'API del WebSocket è stata
standardizzata dal W3C e il protocollo WebSocket è stato
standardizzato dall'IETF come RFC 6455.
WebSocket è disegnato per essere implementato sia lato
browser che lato server, ma può essere utilizzato anche da
qualsiasi applicazione client-server.
Fonte: https://it.wikipedia.org/wiki/WebSocket
43. 43
Streaming – oggetti da utilizzare
ChannelReader<T>
Restituisce un valore non appena disponibile.
ChannelWriter<T>
Consente la scrittura di dati all’interno di uno stream.
55. 55
Azure SignalR Services
SignalR è un servizio completamente gestito.
puoi implementarlo in un ambiente multiserver senza
preoccuparti di:
• hosting,
• scalabilità ,
• bilanciamento del carico
• autenticazione.
60. 60
SignalR - Serverless
Grazie a una estensione per Azure Functions non è
necessario avere la parte server di SignalR su una
applicazione ASP .NET Core.
L’estensione ha grossi limiti, ma per alcuni sceri può essere
utile.
https://github.com/anthonychu/AzureAdvocates.WebJobs.Extensions.SignalRService
Current limitations
•Only supports broadcasting at this time, cannot invoke methods on a subset of connections,
users, or groups
•Functions cannot be triggered by client invocation of server methods (clients need to call an
HTTP endpoint or post messages to a Event Grid, etc, to trigger a function)
Forever Frame creates a hidden IFrame which makes a request to an endpoint on the server that does not complete. The server then continually sends script to the client which is immediately executed, providing a one-way realtime connection from server to client. The connection from client to server uses a separate connection from the server to client connection, and like a standard HTTP request, a new connection is created for each piece of data that needs to be sent.
Crea JWT Token: http://jwtbuilder.jamiekurtz.com/
Port
REST APIs are only exposed on port 5002.
Authentication
In each HTTP request, an authorization header with a JSON Web Token (JWT) is required to authenticate with Azure SignalR Service.
Signing Algorithm and Signature
HS256, namely HMAC-SHA256, is used as the signing algorithm.
You should use the AccessKey in Azure SignalR Service instance's connection string to sign the generated JWT token.
Claims
aud (audience) and exp(expiration time) are required claims in the JWT token.
The aud claim should be exactly the same as your HTTP request url, trailing slash and query paramters not included. For example, a broadcast request's audience should look like as below:
https://example.service.signalr.net:5002/api/v1-preview/hub/myhub
Esempio:
https://github.com/aspnet/AzureSignalR-samples/tree/master/samples/Serverless
Portale
Scalabilita (Up – Out)
ASP .NET Core Secret
Startup progetto
Portale
Scalabilita (Up – Out)
ASP .NET Core Secret
Startup progetto