Real time event feeds with NServiceBus and SignalR

42
Real Time Event Feeds with NServiceBus and SignalR #SIGNALR #NSERVICEBUS #SDE @roycornelissen @marktaling

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 SignalR

Transcript of Real time event feeds with NServiceBus and SignalR

Page 1: Real time event feeds with NServiceBus and SignalR

Real Time Event Feeds

with

NServiceBusand

SignalR#SIGNALR

#NSERVICEBUS

#SDE

@roycornelissen

@marktaling

Page 2: Real time event feeds with NServiceBus and SignalR

NServiceBusCombining

the twoSignalR

Demos

Introduction

Page 3: Real time event feeds with NServiceBus and SignalR
Page 4: Real time event feeds with NServiceBus and SignalR

Showcase: real time monitor

gatewayproduction

monitor

Page 5: Real time event feeds with NServiceBus and SignalR

[connect]

monitor service

Plugins

gateway

SendAvailablePlugins

Powered By

PluginAvailable (3x)

Showcase: real time monitor

Page 6: Real time event feeds with NServiceBus and SignalR
Page 7: Real time event feeds with NServiceBus and SignalR
Page 8: Real time event feeds with NServiceBus and SignalR

NServiceBus

A service bus is an

architectural stylefor integration

To simplify communication between services in a distributed system

Page 9: Real time event feeds with NServiceBus and SignalR

Loose coupling

Share contract and schema, not class

Temporal decoupling through queued messaging

Page 10: Real time event feeds with NServiceBus and SignalR

Where is“the bus”?

Like Ethernet, it’s everywhere!

Page 11: Real time event feeds with NServiceBus and SignalR

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

Page 12: Real time event feeds with NServiceBus and SignalR

developers!

developers!

developers!

Very developer focused

Page 13: Real time event feeds with NServiceBus and SignalR
Page 14: Real time event feeds with NServiceBus and SignalR
Page 15: Real time event feeds with NServiceBus and SignalR
Page 16: Real time event feeds with NServiceBus and SignalR

http has a pull model

Page 17: Real time event feeds with NServiceBus and SignalR

The push concept

The server takes the

initiative to send data

to the client

Page 18: Real time event feeds with NServiceBus and SignalR

Push protocols

irc smtp websocket server sent

events

Page 19: Real time event feeds with NServiceBus and SignalR

Two way, persistent connection, initiated by client

W3C draft, worked on by IETF

Support (partial) in some browsers

Page 20: Real time event feeds with NServiceBus and SignalR

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

Page 21: Real time event feeds with NServiceBus and SignalR

But I want it now!Veruca Salt

Willy Wonka & The Chocolate Factory, 1971

Page 22: Real time event feeds with NServiceBus and SignalR

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”>

Page 23: Real time event feeds with NServiceBus and SignalR

SignalR to the rescue

Page 24: Real time event feeds with NServiceBus and SignalR

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

Page 25: Real time event feeds with NServiceBus and SignalR

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

Page 26: Real time event feeds with NServiceBus and SignalR

hubs

Page 27: Real time event feeds with NServiceBus and SignalR

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

Page 28: Real time event feeds with NServiceBus and SignalR
Page 29: Real time event feeds with NServiceBus and SignalR

SignalR options

JavaScript .NETWindows

PhoneSilverlight WinRT iOS Android

ASP.NET OWIN Custom SQL RedisService

Bus

clients

hosts backplanes

Page 30: Real time event feeds with NServiceBus and SignalR
Page 31: Real time event feeds with NServiceBus and SignalR

Gateway

Monitor Service

Gateway

IIS AppFabric

input

queue

input

queue

MonitorHub: Hub

NServiceBus

MessageForwarder:IHandleMessages<T>

GlobalHost.ConnectionManager.GetHubContext<MonitorHub>();.

Page 32: Real time event feeds with NServiceBus and SignalR
Page 33: Real time event feeds with NServiceBus and SignalR

Transport

Monitor Service

Gateway

IIS AppFabric

SignalRNServiceBus

MonitorHub: HubNServiceBus

Page 34: Real time event feeds with NServiceBus and SignalR
Page 35: Real time event feeds with NServiceBus and SignalR

Transparent: no

notion of SignalR

NServiceBus in

the client

SignalR transport

The Good

Page 36: Real time event feeds with NServiceBus and SignalR

No guaranteed

delivery

No transaction

support

SignalR transport

The Bad

Page 37: Real time event feeds with NServiceBus and SignalR

Scaling out SignalR via backplanes

B

NServiceBus

?

Page 38: Real time event feeds with NServiceBus and SignalR

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

Page 39: Real time event feeds with NServiceBus and SignalR
Page 40: Real time event feeds with NServiceBus and SignalR

Reliability offered

by NServiceBus

What about

scalability of the

backplane service

itself?

SignalR backplane

Considerations

Page 41: Real time event feeds with NServiceBus and SignalR

Linkswww.nuget.org

www.nservicebus.com

www.github.com/nservicebus

www.udidahan.com

www.github.com/signalr

www.github.com/gshackles/signalr

Page 42: Real time event feeds with NServiceBus and SignalR

@roycornelissen

[email protected]

roycornelissen.wordpress.com

thanks!

@marktaling

[email protected]