Show you NServiceBus (Running on premises)◦ Why it’s scalable◦ Why it’s productive (awesome sauce)
Show you how to move it to Azure Show you how to avoid Azure’s traps
The Plan™
Also known as “Hub and Spoke” and “Mediator” Designed to avoid having to change apps – EAI
Broker Architectural Style
App 7Broker
App 6
App 5 App 4
App 3
App 2
App 1App 9App 8
Event source and sinks use bus for pub/sub Designed to allow independent evolution of
sources and sinks
Bus Architectural Style
Sink
Source Sink
Source
Bus
What is a Service Bus?
There is no bus…
Bus TopologyApp
Bus.dll
App
Bus.dll
App
Bus.dll
App
Bus.dll
App
Bus.dll
App
Bus.dll
App
Bus.dll
App
Bus.dll
Send Commands Publish Events Processing Pipelines Sagas Unit Testing
Features & Patterns
Messaging & Queues
Server
Client
Logically one-way:
All information transferred inthe message
Messaging & QueuesMSMQ
Outgoing Incoming
Server
Client
MSMQOutgoing
Incoming
Store & Forward writes to diskResilient in the face of failures
Modelled as a command Tell someone to do something
Messaging & Queues
Host Send Command
Demo
• Subscription Storage
• Saga Persistence• Hosting
Publisher
Subscriber
Subscribe
Subscriber
Subscriber
Subscriber
Subscriber
Publisher
Subscriber
Subscriber
Subscriber
Subscriber
Subscriberabcdefgh
abcdefgh
abcdefgh
abcdefgh
abcdefgh
Modelled as events Let everyone (or anyone) know something
happened
Pub /Sub
Pub Sub
Demo
• Subscription Storage
• Saga Persistence• Hosting
Order Service
Billing Service
Place Order Handler
Takes Order
Customer Care Service
Place Order
Order Placed
Order Placed HandlerBills Customer when Max Debt
Reached
Customer Billed
Order Confirmation Handler
Sends confirmation email to customer
Customer Billed
Pipelines & Polymorhpism
Order Service
Billing Service
Place Order Handler
Takes Order
Customer Care Service
Welcome New Customer Handler
Sends Catalogue & Welome Pack To New Customer
Place Order
First Order Placed
Customer Welcomed
Order Placed HandlerBills Customer when Max Debt
Reached
Customer Billed
Order Confirmation Handler
Sends confirmation email to customer
Customer Billed
Pipelines & Polymorhpism
Pipelines & Polymorphism
Demo
• Subscription Storage
• Saga Persistence• Hosting
Decisions Based on Past EventsPlace Order
Order Service
Billing Service
Order Placed
Customer Billed
Set Max Debit For Customer
Current Debt > Max Debt
Customer IDMax Debt
Current Balance
Sagas
Demo
• Subscription Storage
• Saga Persistence• Hosting
Queues Subscription
Storage Saga Persistence Hosting
Local Infrastructure
Queues
On Premises Infrastructure
MSMQs
Subscription Storage Saga Persistence
On Premises Infrastructure
• Subscription Storage
• Saga Persistence• Hosting
Hosting
On Premises Infrastructure
• Subscription Storage
• Saga Persistence• Hosting
Platform Queues SubscriptionStorage
Saga Persistence
Hosting
Windows MSMQ RavenDBNHibernate
SQL ServerOracleEtc.
RavenDBNhibernate
SQL ServerOracleEtc.
TopShelfIIS
Windows Azure
Queue StorageApp Fabric Queues
Table StorageNHibernate
Sql Azure
Table StorageNHibernate
Sql Azure
NSB Azure HostWeb Core IIS
Infrastructure Options
Move it to Azure
Demo
Storage Queues and App Fabric Queues
Built in back off of polling to reduce cost
Queuing with Azure
Storage Queues do not support transactions Queue Peek Lock Possible multiple processing so need to be
idempotent Limit imposed Small payload size Can use data bus to get over size limit
Queuing with Storage Queues
Supports for exactly once delivery Higher Message Size No throughput limits imposed
Queuing with App Fabric Queues
Runs in a Worker Role
Dedicated Hosting
Runs in a Worker Role Loads zip packages from blob storage
Shared Hosting
Runs in a Web Role Loads zip packages from blob storage You can run workers in a web role
Web Workers
Will create the schema for you via NHibernate
Remember Table Storage type limitations
Sagas
The biggest challenge in Azure vs. On Premise
Several strategies available◦ Idempotence◦ Sagas
Lack of Transactions & DTC
Messaging and Consistency – On Premises
DTxQ$$ Order
Handler
Receive
DBDecrement Account
Rollback
Decrement Inventory
Rollback
The order is back in the queue
Some Operation
Messaging and Consistency – On Premises
DTxQ$$ Order
Handler
Receive
DBDecrement AccountDecrement Inventory
DB in consistent state
Record Order
We retry
Messaging and Consistency – On Azure
QPLQ$$ Order
Handler
Receive
DBDecrement Account
2 txns commit
Decrement Inventory
Some Operation
Rollback
The order is back in the queueBut DB Has been written
Messaging and Consistency – On Azure
QPLQ
Handler
Receive
DBDecrement Account
Decrement Inventory
Now account & inventory decremented twice
Record Order
3 txns commitWe retry
Messaging and Consistency – QPL Timeouts
QPLQ$$ Order
Handler
Receive
DB
Some operation request
Some operation response
The order is back in the queue
QPL Timout
Messaging and Consistency – QPL Timeouts
QPLQ$$ Order
Handler
Receive
DB
Some operation request
Some operation response
The order is back in the queue
QPL Timout
Messaging and Consistency – QPL Timeouts
QPLQ$$ Order
Handler
Receive
DB
Some operation request
Some operation response
Operation has been run twice
We retry
Messaging and Consistency – On AzureAn example of idempotence
QPLQ$$ Order
Handler
Receive
DB
Check for debit record
2 operations committed
Add debit to account ledger
Rollback
The order is back in the queue
Check for outwards inventory movement
Add outward inventory movement
Some Operation
QPL Timout
QPLQ$$ Order
Handler
Receive
DB
Check for debit record
1 operation committed
3 operations committed totalDB is in a consistent state
Check for outwards inventory movement
Check record of order
Add record for order
Messaging and Consistency – On AzureAn example of idempotence
Multiple operations can get gnarly quick!
Use idempotence Track state of remote op with saga
◦ Success – Do nothing (we’re already done)◦ Pending – Try again (we might still fail)◦ Failure - Compensate
Keeping Azure Consistant
http://www.nservicebus.com/Documentation.aspx
http://cloudshaper.wordpress.com/ http://tech.groups.yahoo.com/group/nservicebus
Resources
Enterprise Development with NServiceBus
A 3 day course on NSB written by Udi Dahan & delivered by yours truly
http://nsbdecember2012.eventbrite.com.au/
The Plug
Jim Pelletier@pjimmy