460 likes | 669 Views
NserviceBus on Azure. Jim Pelletier @ pjimmy mail@thejimmyp.com. The Plan™. 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. Broker Architectural Style.
E N D
NserviceBus on Azure Jim Pelletier @pjimmy mail@thejimmyp.com
The Plan™ • 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
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 App App Bus.dll Bus.dll Bus.dll Bus.dll App App App App Bus.dll Bus.dll 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 MSMQ OutgoingIncoming Store & Forward writes to disk Resilient in the face of failures MSMQ OutgoingIncoming Client
Messaging & Queues • Modelled as a command • Tell someone to do something
Demo • Host • Send Command • Subscription Storage • Saga Persistence • Hosting
Subscriber Publisher Subscribe Subscriber Subscriber Subscriber Subscriber
Subscriber Publisher abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh Subscriber Subscriber Subscriber Subscriber
Pub /Sub • Modelled as events • Let everyone (or anyone) know something happened
Demo • Pub Sub • Subscription Storage • Saga Persistence • Hosting
Pipelines & Polymorhpism Order Placed Order Service Place Order Handler Takes Order Place Order Billing Service Customer Billed Order Placed Handler Bills Customer when Max Debt Reached Customer Care Service Order Confirmation Handler Sends confirmation email to customer Customer Billed
Pipelines & Polymorhpism First Order Placed Order Service Place Order Handler Takes Order Place Order Billing Service Customer Billed Order Placed Handler Bills Customer when Max Debt Reached Customer Care Service Order Confirmation Handler Sends confirmation email to customer Customer Billed Welcome New Customer Handler Sends Catalogue & Welome Pack To New Customer Customer Welcomed
Demo • Pipelines & Polymorphism • Subscription Storage • Saga Persistence • Hosting
Decisions Based on Past Events Order Service Place Order Order Placed Billing Service Current Debt > Max Debt Customer Billed Customer ID Max Debt Current Balance Set Max Debit For Customer
Demo • Sagas • Subscription Storage • Saga Persistence • Hosting
Local Infrastructure • Queues • Subscription Storage • Saga Persistence • Hosting
On Premises Infrastructure • Queues MSMQs
On Premises Infrastructure • Subscription Storage • Saga Persistence • Subscription Storage • Saga Persistence • Hosting
On Premises Infrastructure • Hosting • Subscription Storage • Saga Persistence • Hosting
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 DTx Q Receive Handler DB Decrement Inventory $$ Order Decrement Account Some Operation Rollback Rollback The order is back in the queue
Messaging and Consistency – On Premises We retry DTx Q Receive Handler DB Decrement Inventory $$ Order Record Order Decrement Account DB in consistent state
Messaging and Consistency – On Azure QPL Q Receive Handler DB Decrement Inventory $$ Order Decrement Account Some Operation Rollback 2 txns commit The order is back in the queue But DB Has been written
Messaging and Consistency – On Azure We retry QPL Q Receive Handler DB Decrement Account Record Order Decrement Inventory 3txns commit Now account & inventory decremented twice
Messaging and Consistency – QPL Timeouts QPL Timout QPL Q Receive DB Handler Some operation response Some operation request $$ Order The order is back in the queue
Messaging and Consistency – QPL Timeouts QPL Timout QPL Q Receive DB Handler Some operation response Some operation request $$ Order The order is back in the queue
Messaging and Consistency – QPL Timeouts We retry QPL Q Receive DB Handler Some operation response Some operation request $$ Order Operation has been run twice
Messaging and Consistency – On AzureAn example of idempotence QPL Timout QPL Q Receive DB Handler Check for outwards inventory movement Check for debit record Add outward inventory movement Add debit to account ledger $$ Order Some Operation 2 operations committed The order is back in the queue Rollback
Messaging and Consistency – On AzureAn example of idempotence QPL Q Receive DB Handler Check record of order Check for outwards inventory movement Check for debit record Add record for order $$ Order 1 operation committed 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 NServiceBus A 3 day course on NSB written by UdiDahan & delivered by yours truly http://nsbdecember2012.eventbrite.com.au/ Jim Pelletier @pjimmy mail@thejimmyp.com