46
NserviceBus on Azure Jim Pelletier @pjimmy [email protected]

NserviceBus on Azure

  • Upload
    mandel

  • View
    56

  • Download
    6

Embed Size (px)

DESCRIPTION

NserviceBus on Azure. Jim Pelletier @ pjimmy [email protected]. 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. - PowerPoint PPT Presentation

Citation preview

Page 1: NserviceBus  on Azure

NserviceBus on AzureJim Pelletier

@[email protected]

Page 2: NserviceBus  on Azure

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™

Page 3: NserviceBus  on Azure

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

Page 4: NserviceBus  on Azure

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

Page 5: NserviceBus  on Azure

What is a Service Bus?

There is no bus…

Page 6: NserviceBus  on Azure

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

Page 7: NserviceBus  on Azure

Send Commands Publish Events Processing Pipelines Sagas Unit Testing

Features & Patterns

Page 8: NserviceBus  on Azure

Messaging & Queues

Server

Client

Logically one-way:

All information transferred inthe message

Page 9: NserviceBus  on Azure

Messaging & QueuesMSMQ

Outgoing Incoming

Server

Client

MSMQOutgoing

Incoming

Store & Forward writes to diskResilient in the face of failures

Page 10: NserviceBus  on Azure

Modelled as a command Tell someone to do something

Messaging & Queues

Page 11: NserviceBus  on Azure

Host Send Command

Demo

• Subscription Storage

• Saga Persistence• Hosting

Page 12: NserviceBus  on Azure

Publisher

Subscriber

Subscribe

Subscriber

Subscriber

Subscriber

Subscriber

Page 13: NserviceBus  on Azure

Publisher

Subscriber

Subscriber

Subscriber

Subscriber

Subscriberabcdefgh

abcdefgh

abcdefgh

abcdefgh

abcdefgh

Page 14: NserviceBus  on Azure

Modelled as events Let everyone (or anyone) know something

happened

Pub /Sub

Page 15: NserviceBus  on Azure

Pub Sub

Demo

• Subscription Storage

• Saga Persistence• Hosting

Page 16: NserviceBus  on Azure

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

Page 17: NserviceBus  on Azure

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

Page 18: NserviceBus  on Azure

Pipelines & Polymorphism

Demo

• Subscription Storage

• Saga Persistence• Hosting

Page 19: NserviceBus  on Azure

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

Page 20: NserviceBus  on Azure

Sagas

Demo

• Subscription Storage

• Saga Persistence• Hosting

Page 21: NserviceBus  on Azure

Queues Subscription

Storage Saga Persistence Hosting

Local Infrastructure

Page 22: NserviceBus  on Azure

Queues

On Premises Infrastructure

MSMQs

Page 23: NserviceBus  on Azure

Subscription Storage Saga Persistence

On Premises Infrastructure

• Subscription Storage

• Saga Persistence• Hosting

Page 24: NserviceBus  on Azure

Hosting

On Premises Infrastructure

• Subscription Storage

• Saga Persistence• Hosting

Page 25: NserviceBus  on Azure

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

Page 26: NserviceBus  on Azure

Move it to Azure

Demo

Page 27: NserviceBus  on Azure

Storage Queues and App Fabric Queues

Built in back off of polling to reduce cost

Queuing with Azure

Page 28: NserviceBus  on 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

Page 29: NserviceBus  on Azure

Supports for exactly once delivery Higher Message Size No throughput limits imposed

Queuing with App Fabric Queues

Page 30: NserviceBus  on Azure

Runs in a Worker Role

Dedicated Hosting

Page 31: NserviceBus  on Azure

Runs in a Worker Role Loads zip packages from blob storage

Shared Hosting

Page 32: NserviceBus  on Azure

Runs in a Web Role Loads zip packages from blob storage You can run workers in a web role

Web Workers

Page 33: NserviceBus  on Azure

Will create the schema for you via NHibernate

Remember Table Storage type limitations

Sagas

Page 34: NserviceBus  on Azure

The biggest challenge in Azure vs. On Premise

Several strategies available◦ Idempotence◦ Sagas

Lack of Transactions & DTC

Page 35: NserviceBus  on Azure

Messaging and Consistency – On Premises

DTxQ$$ Order

Handler

Receive

DBDecrement Account

Rollback

Decrement Inventory

Rollback

The order is back in the queue

Some Operation

Page 36: NserviceBus  on Azure

Messaging and Consistency – On Premises

DTxQ$$ Order

Handler

Receive

DBDecrement AccountDecrement Inventory

DB in consistent state

Record Order

We retry

Page 37: NserviceBus  on Azure

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

Page 38: NserviceBus  on Azure

Messaging and Consistency – On Azure

QPLQ

Handler

Receive

DBDecrement Account

Decrement Inventory

Now account & inventory decremented twice

Record Order

3 txns commitWe retry

Page 39: NserviceBus  on Azure

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

Page 40: NserviceBus  on Azure

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

Page 41: NserviceBus  on Azure

Messaging and Consistency – QPL Timeouts

QPLQ$$ Order

Handler

Receive

DB

Some operation request

Some operation response

Operation has been run twice

We retry

Page 42: NserviceBus  on Azure

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

Page 43: NserviceBus  on Azure

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

Page 44: NserviceBus  on Azure

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

Page 46: NserviceBus  on Azure

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

[email protected]