Nservice Bus on Azure Jim Pelletier pjimmy mailthejimmyp
Nservice. Bus on Azure Jim Pelletier @pjimmy mail@thejimmyp. com
The Plan™ Show you NService. Bus (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
Broker Architectural Style Also known as “Hub and Spoke” and “Mediator” Designed to avoid having to change apps – EAI App 8 App 1 App 9 App 7 App 2 Broker App 6 App 3 App 5 App 4
Bus Architectural Style Event source and sinks use bus for pub/sub Designed to allow independent evolution of sources and sinks Source Sink Bus Sink Source
What is a Service Bus? There is no bus…
Bus Topology App App Bus. dll Bus. dll
Features & Patterns Send Commands Publish Events Processing Pipelines Sagas Unit Testing
Messaging & Queues Server Logically one-way: All information transferred in the message Client
Messaging & Queues Server Outgoing MSMQ Incoming Store & Forward writes to disk Resilient in the face of failures Outgoing MSMQ Client Incoming
Messaging & Queues Modelled as a command Tell someone to do something
Demo Host Send Command • Subscription Storage • Saga Persistence • Hosting
Subscriber Publisher Subscriber Subscriber
Subscriber Publisher abcdefgh Subscriber abcdefgh Subscriber
Pub /Sub Modelled as events Let everyone (or anyone) know something happened
Demo Pub Sub • Subscription Storage • Saga Persistence • Hosting
Pipelines & Polymorhpism Place Order Service Place Order Handler Takes Order Billing Service Order Placed Handler Bills Customer when Max Debt Reached Customer Billed Customer Care Service Order Confirmation Handler Sends confirmation email to customer Order Placed Customer Billed
Pipelines & Polymorhpism Place Order Service Place Order Handler Takes Order Billing Service Order Placed Handler Bills Customer when Max Debt Reached Customer Billed Customer Care Service Order Confirmation Handler Sends confirmation email to customer Welcome New Customer Handler Sends Catalogue & Welome Pack To New Customer First Order Placed Customer Billed Customer Welcomed
Demo Pipelines & Polymorphism • Subscription Storage • Saga Persistence • Hosting
Decisions Based on Past Events Place Order Service Billing Service Customer Billed Current Debt > Max Debt Customer ID Max Debt Set Max Debit For Customer Current Balance Order Placed
Demo Sagas • Subscription Storage • Saga Persistence • Hosting
Local Infrastructure Queues Subscription Storage Saga Persistence Hosting
On Premises Infrastructure Queues MSMQ s
On Premises Infrastructure Subscription Storage Saga Persistence • Subscription Storage • Saga Persistence • Hosting
On Premises Infrastructure Hosting • Subscription Storage • Saga Persistence • Hosting
Infrastructure Options Platform Queues Subscription Storage Saga Persistence Hosting Windows MSMQ Raven. DB NHibernate SQL Server Oracle Etc. Raven. DB Nhibernate SQL Server Oracle Etc. Top. Shelf IIS Windows Azure Queue Storage App Fabric Queues Table Storage NHibernate Sql Azure NSB Azure Host Web Core IIS
Demo Move it to Azure
Queuing with Azure Storage Queues and App Fabric Queues Built in back off of polling to reduce cost
Queuing with Storage Queues 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 App Fabric Queues Supports for exactly once delivery Higher Message Size No throughput limits imposed
Dedicated Hosting Runs in a Worker Role
Shared Hosting Runs in a Worker Role Loads zip packages from blob storage
Web Workers Runs in a Web Role Loads zip packages from blob storage You can run workers in a web role
Sagas Will create the schema for you via NHibernate Remember Table Storage type limitations
Lack of Transactions & DTC The biggest challenge in Azure vs. On Premise Several strategies available ◦ Idempotence ◦ Sagas
Messaging and Consistency – On Premises $$ Order Q Rollback DTx Receive Rollback Handler Decrement Account Decrement Inventory DB Some Operation The order is back in the queue
Messaging and Consistency – On Premises We retry $$ Order Q DTx Receive Handler Decrement Account Decrement Inventory Record Order DB DB in consistent state
Messaging and Consistency – On Azure $$ Order Q 2 txns commit QPL Receive Rollback Handler Decrement Account Decrement Inventory DB Some Operation The order is back in the queue But DB Has been written
Messaging and Consistency – On Azure We retry Q 3 txns commit QPL Receive Handler Decrement Account Decrement Inventory Record Order DB Now account & inventory decremented twice
Messaging and Consistency – QPL Timeouts $$ Order QPL Q Timout Receive Handler Some operation request Some operation response DB The order is back in the queue
Messaging and Consistency – QPL Timeouts $$ Order QPL Q Timout Receive Handler Some operation request Some operation response DB The order is back in the queue
Messaging and Consistency – QPL Timeouts We retry $$ Order Q QPL Receive Handler Some operation request Some operation response DB Operation has been run twice
Messaging and Consistency – On Azure An example of idempotence $$ Order 2 operations committed QPL Q Timout Receive Rollback Check for debit record Handler Add debit to account ledger Check for outwards inventory movement Add outward inventory movement DB Some Operation The order is back in the queue
Messaging and Consistency – On Azure An example of idempotence $$ Order Q 1 operation committed QPL Receive Check for debit record Handler Check for outwards inventory movement DB Check record of order Add record for order 3 operations committed total DB is in a consistent state
Keeping Azure Consistant 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
Resources http: //www. nservicebus. com/Documentation. aspx http: //cloudshaper. wordpress. com/ http: //tech. groups. yahoo. com/group/nservicebus
The Plug Enterprise Development with NService. Bus A 3 day course on NSB written by Udi Dahan & delivered by yours truly http: //nsbdecember 2012. eventbrite. com. au/ Jim Pelletier @pjimmy mail@thejimmyp. com
- Slides: 46