real time event feeds with nservicebus and signalr
DESCRIPTION
Session for SDN Event. In this session Mark Taling and I explain how we used NServiceBus and SignalR to publish real time events from a production monitor. After a short intro to NServiceBus and SignalR, we dive into some techniques for combining the two: 1) SignalR for relaying events from the back end to a wide range of clients 2) Using SignalR as a transport for NServiceBus 3) Using NServiceBus as a backplane for scaling out SignalRTRANSCRIPT
Real Time Event Feeds
with
NServiceBusand
SignalR#SIGNALR
#NSERVICEBUS
#SDE
@roycornelissen
@marktaling
NServiceBusCombining
the twoSignalR
Demos
Introduction
Showcase: real time monitor
gatewayproduction
monitor
[connect]
monitor service
Plugins
gateway
SendAvailablePlugins
Powered By
PluginAvailable (3x)
Showcase: real time monitor
NServiceBus
A service bus is an
architectural stylefor integration
To simplify communication between services in a distributed system
Loose coupling
Share contract and schema, not class
Temporal decoupling through queued messaging
Where is“the bus”?
Like Ethernet, it’s everywhere!
A .NET framework to help implement SOA with the Service Bus architectural style
Abstracts away transport, threading, queues, transactions
Focuses on implementing business logic
Highly pluggable
developers!
developers!
developers!
Very developer focused
http has a pull model
The push concept
The server takes the
initiative to send data
to the client
Push protocols
irc smtp websocket server sent
events
Two way, persistent connection, initiated by client
W3C draft, worked on by IETF
Support (partial) in some browsers
Server side events
“Pub/Sub” like protocol over http
Also still a W3C draft
One-way, client needs extra channel for send
Proxies need to know about content-type:text/event-stream
But I want it now!Veruca Salt
Willy Wonka & The Chocolate Factory, 1971
Other options
client 2
server
POST “message”
client 1Got msg? “message”
long polling
POST “message”
Got msg? “message”
client 2
server
POST “message”
client 1GET /forever
<script>
display(“message”);
</script>
forever frame
POST “message”
<script>
display(“message”);
</script>
<iframe src=“/forever”>
SignalR to the rescue
SignalR’s layers of abstraction
SignalR will abstract away the
actual protocol used, and adds
a couple of layers on top to
make things even easier
protocols
persistent connection
hub
web sockets server events long polling forever frame
• Unified programming model
• Deals with connectivity issues (connection slow, reconnect, disconnects)
• Available for multiple types of clients
• Messaging bus
• Utilizes Json.NET for serialization
SignalR 1.0
hubs
Client/server boundaries fadeHubs let you provide a semantic API between client and server
SignalR creates a proxy between the two parties
client (javascript)
var chat = $.connection.chatHub;
…
chat.server.message(“hi!”);
…
chat.client.notify = function(text) {
// do something with text
}
server
class ChatHub: Hub
{
public void message(string text)
{
Clients.All.notify(text);
}
}
proxy
dynamic
SignalR options
JavaScript .NETWindows
PhoneSilverlight WinRT iOS Android
ASP.NET OWIN Custom SQL RedisService
Bus
clients
hosts backplanes
Gateway
Monitor Service
Gateway
IIS AppFabric
input
queue
input
queue
MonitorHub: Hub
NServiceBus
MessageForwarder:IHandleMessages<T>
GlobalHost.ConnectionManager.GetHubContext<MonitorHub>();.
Transport
Monitor Service
Gateway
IIS AppFabric
SignalRNServiceBus
MonitorHub: HubNServiceBus
Transparent: no
notion of SignalR
NServiceBus in
the client
SignalR transport
The Good
No guaranteed
delivery
No transaction
support
SignalR transport
The Bad
Scaling out SignalR via backplanes
B
NServiceBus
?
An NServiceBus backplane
Backplane ServiceSignalR
IIS AppFabric
input
queue
NServiceBusMessageBus: ScaleoutMessageBus
NServiceBus
Receiver: IHandleMessages<MessagesAvailable>
Bus.Send<DistributeMessage>()
MessageDispatcher: IHandleMessages<DistributeMessage>
Bus.Publish<MessagesAvailable>()
OnReceived(…);.
input
queue
Reliability offered
by NServiceBus
What about
scalability of the
backplane service
itself?
SignalR backplane
Considerations
Linkswww.nuget.org
www.nservicebus.com
www.github.com/nservicebus
www.udidahan.com
www.github.com/signalr
www.github.com/gshackles/signalr
@roycornelissen
roycornelissen.wordpress.com
thanks!
@marktaling