Real time event feeds with NServiceBus and SignalR


Published on

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 SignalR

Published in: Technology
  • Be the first to comment

Real time event feeds with NServiceBus and SignalR

  1. 1. Real Time Event Feeds withNServiceBus and @roycornelissen SignalR #SIGNALR #NSERVICEBUS @marktaling #SDE
  2. 2. CombiningIntroduction NServiceBus SignalR the two Demos
  3. 3. Showcase: real time monitor production gateway monitor
  4. 4. Showcase: real time monitor monitor service gateway Plugins SendAvailablePlugins PluginAvailable (3x) [connect]Powered By
  5. 5. A service bus is anarchitectural style for integrationTo simplify communication between services in a distributed system NServiceBus
  6. 6. Loose couplingShare contract and schema, not classTemporal decoupling through queued messaging
  7. 7. Where is “the bus”?Like Ethernet, it’s everywhere!
  8. 8. A .NET framework to help implement SOAwith the Service Bus architectural styleAbstracts away transport, threading,queues, transactionsFocuses on implementing business logicHighly pluggable
  9. 9. developers! developers!developers! Very developer focused
  10. 10. http has a pull model
  11. 11. The push conceptThe server takes theinitiative to send datato the client
  12. 12. Push protocols irc smtp websocket server sent events
  13. 13. Two way, persistent connection, initiatedby clientW3C draft, worked on by IETFSupport (partial) in some browsers
  14. 14. Server side events“Pub/Sub” like protocol over httpAlso still a W3C draftOne-way, client needs extra channel for sendProxies need to know aboutcontent-type:text/event-stream
  15. 15. But I want it now! Veruca Salt Willy Wonka & The Chocolate Factory, 1971
  16. 16. Other options long pollingclient 1 Got msg? “message” Got msg? “message”server POST “message” POST “message”client 2 forever frame <iframe src=“/forever”>client 1 <script> <script> GET /forever display(“message”); display(“message”); </script> </script>server POST “message” POST “message”client 2
  17. 17. SignalR to the rescue
  18. 18. SignalR will abstract away theactual protocol used, and addsa couple of layers on top tomake things even easierSignalR’s layers of abstraction
  19. 19. hub persistent connectionSignalR 1.0 protocols 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
  20. 20. hubs
  21. 21. Client/server boundaries fade Hubs let you provide a semantic API between client and server SignalR creates a proxy between the two parties client (javascript) server var chat = $.connection.chatHub; class ChatHub: Hub … { chat.server.message(“hi!”); proxy public void message(string text) … { chat.client.notify = function(text) Clients.All.notify(text); { } // do something with text } } dynamic
  22. 22. SignalR options clients WindowsJavaScript .NET Silverlight WinRT iOS Android Phone ServiceASP.NET OWIN Custom SQL Redis Bus hosts backplanes
  23. 23. Gateway input queue Gateway Monitor Service MonitorHub: Hub GlobalHost .ConnectionManager NServiceBus .GetHubContext<MonitorHub>();. input queue MessageForwarder: IHandleMessages<T> IIS AppFabric
  24. 24. Transport Gateway Monitor ServiceNServiceBus MonitorHub: Hub NServiceBus SignalR IIS AppFabric
  25. 25. SignalR transport The Good Transparent: nonotion of SignalR NServiceBus in the client
  26. 26. SignalR transport The BadNo guaranteed deliveryNo transaction support
  27. 27. Scaling out SignalR via backplanes ? B NServiceBus
  28. 28. An NServiceBus backplane input queue Backplane Service SignalR MessageDispatcher: IHandleMessages<DistributeMessage> NServiceBusMessageBus: Bus.Send<DistributeMessage>() ScaleoutMessageBus NServiceBus OnReceived(…);. input Bus.Publish<MessagesAvailable>() queue Receiver: IHandleMessages<MessagesAvailable> IIS AppFabric
  29. 29. SignalR backplaneConsiderationsReliability offeredby NServiceBusWhat aboutscalability of thebackplane serviceitself?
  30. 30. Links
  31. 31. thanks!