58
NServiceBus On Azure

NSBCon UK nservicebus on Azure by Yves Goeleven

Embed Size (px)

DESCRIPTION

NSBCon UK nservicebus on Azure by Yves Goeleven

Citation preview

Page 1: NSBCon UK nservicebus on Azure by Yves Goeleven

NServiceBus On Azure

Page 2: NSBCon UK nservicebus on Azure by Yves Goeleven

Yves GoelevenFounder of MessageHandler.net

• Developer on NServiceBus

• Windows Azure MVP

• @YvesGoeleven

Page 3: NSBCon UK nservicebus on Azure by Yves Goeleven

AgendaNServiceBus on Azure

• Tour d’Azure• Hosting options• Transports • Persistence • Tips & tricks || Q&A

Page 4: NSBCon UK nservicebus on Azure by Yves Goeleven

Tour d’Azure

Page 5: NSBCon UK nservicebus on Azure by Yves Goeleven

Why people are interested in Azure? Various reasons

• Automated, • Scalability (scale out)• Elasticity (scale in again)• Cost• Globally available

Page 6: NSBCon UK nservicebus on Azure by Yves Goeleven

NServiceBus & Azure: Perfect matchAll this goodness comes at a cost though

• Serious learning curve• Different development paradigm• Need to understand infrastructure

• NServiceBus helps reduce that learning curve, • makes it easy to develop for Azure

Page 7: NSBCon UK nservicebus on Azure by Yves Goeleven

What is Azure?Global network of huge data centers operated by Microsoft

Page 8: NSBCon UK nservicebus on Azure by Yves Goeleven
Page 9: NSBCon UK nservicebus on Azure by Yves Goeleven
Page 10: NSBCon UK nservicebus on Azure by Yves Goeleven

Some numbersJust to illustrate how huge it is

• 13 regions• 321 IP ranges• 250.000+ customers• 2.000.000+ VM’s• 25+ trillion objects stored

Page 11: NSBCon UK nservicebus on Azure by Yves Goeleven

200 services running on top

Storage Big data

Caching CDN

Database

Identity

Media Networking

Traffic

Messaging

Cloud ServicesWeb Sites

Connectivity

MobileVirtual Machines

Page 12: NSBCon UK nservicebus on Azure by Yves Goeleven

ImplicationsOf such a huge network

• Latency is normal• Machine failure is normal• Network partitioning is normal• No distributed transactions!

Page 13: NSBCon UK nservicebus on Azure by Yves Goeleven

ImplicationsOf ‘as a service’ model

• Microsoft doesn’t trust you!• Individual resources are limited• Throttling• Your resources are moved around• Unpredictable resource performance• Transient errors• No locks or very short locks• No local transactions!

• 1 exception: Sql as it is build into the protocol

Page 14: NSBCon UK nservicebus on Azure by Yves Goeleven

How to deal with itNServiceBus helps a lot, but you need to code to it as well

• Retry, retry, retry!• Pick a transport that retries instead of relying on transactions• Enable First Level Retry• Enable Second Level Retry

Page 15: NSBCon UK nservicebus on Azure by Yves Goeleven

How to deal with itNServiceBus helps a lot, but you need to code to it as well

• Take care of idempotency• Atomic messagehandler implementations• Saga’s too! Update saga state & nothing else!• Use saga’s to coordinate compensation logic• Check for retries• Check side effects

See, http://docs.particular.net/nservicebus/understanding-transactions-in-windows-azure for more options

Page 16: NSBCon UK nservicebus on Azure by Yves Goeleven

How to deal with itDo not trust your disk!

• Do not put anything on disk!• The machine will fail, the disk will be gone!• Anyone noticed there is no SLA for individual VM’s?

• Put your stuff in storage• 99.99% SLA• Local Redundant & Geo Redunant

Page 17: NSBCon UK nservicebus on Azure by Yves Goeleven

Hosting options

Page 18: NSBCon UK nservicebus on Azure by Yves Goeleven

3 hosting optionsSame underlying infrastructure, built on top of each other

Cloud services Web sites Virtual Machines

Page 19: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud services

Page 20: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud servicesMany identical vm’s managed by azure

• Stateless• Based on a template (role)• Includes agents

• Health reporting• Diagnostics collection• Runtime & configuration environment

Page 21: NSBCon UK nservicebus on Azure by Yves Goeleven

ServicePackage

ServicePackage

Page 22: NSBCon UK nservicebus on Azure by Yves Goeleven

ServicePackage

Server Rack 1 Server Rack 2

Virtual machine

Virtual machine

Provision Role InstancesDeploy App CodeConfigure Network

Virtual machine

Virtual machine

Page 23: NSBCon UK nservicebus on Azure by Yves Goeleven

Windows Azure Datacenter

ServicePackage

Provision Role InstancesDeploy App CodeConfigure Network

Page 24: NSBCon UK nservicebus on Azure by Yves Goeleven

Windows Azure Datacenter

ServicePackage

Provision Role InstancesDeploy App CodeConfigure Network

Page 25: NSBCon UK nservicebus on Azure by Yves Goeleven

Network Load Balancer

Windows Azure Datacenter

Network load-balancer configured for traffic

Provision Role InstancesDeploy App CodeConfigure Network

Page 26: NSBCon UK nservicebus on Azure by Yves Goeleven

Network Load Balancer

Windows Azure Datacenter

Page 27: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud servicesSpecific NServiceBus host

• Make use of agents present on the vm• Runtime & configuration environment• Diagnostics

• Found in NServiceBus.Hosting.Azure

Page 28: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud servicesUse NServiceBusRoleEntrypoint

• Just call start & stop

public class WorkerRole : RoleEntryPoint{ private readonly NServiceBusRoleEntrypoint nsb = new NServiceBusRoleEntrypoint();

public override bool OnStart() { nsb.Start(); return base.OnStart(); }

public override void OnStop() { nsb.Stop(); base.OnStop(); }}

Page 29: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud servicesAnd Configure your endpoint as a worker

• AsA_Worker: Specific profile, similar to AsA_Publisher on-premises but different defaults

• Configured for local emulator by default• Don’t forget to change config settings before deploying to azure itself

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureServiceBus>{}

Page 30: NSBCon UK nservicebus on Azure by Yves Goeleven

Cloud servicesIs designed for massive scale, what if you don’t need that

• AsA_Host: Specific profile for colocation

• Reference nservicebus.hosting.azure.hostprocess from your AsA_Worker endpoint• Zip your endpoint & put in blob storage container

• AsA_Host endpoint will • Download them on startup• Run them• Manage them (including updates)

public class EndpointConfig : IConfigureThisEndpoint, AsA_Host{}

Page 31: NSBCon UK nservicebus on Azure by Yves Goeleven

Virtual Machines

Page 32: NSBCon UK nservicebus on Azure by Yves Goeleven

Virtual MachinesJust like regular VM’s, except

• Built on cloud services, yet single VM• No SLA unless you run multiple (stateless) copies

• You manage the os• You are responsible for failover & backups!

• Disk persisted remotely• In azure storage services• No local write cache by default, subject to throttling• Impacts IOPS• May loose local data during geo disaster

• 1 minute local replication (lease held by original node)• 5 minute geo-replication SLA• Happened 3 times in past 5 years, no data loss yet

Page 33: NSBCon UK nservicebus on Azure by Yves Goeleven

Virtual MachinesRegular NServiceBus host can be used, but

• Do not setup DTC

• Do not rely on transports that rely on DTC • no msmq

• If you use other transports that rely on local disk• Make sure they are configured for failover or clustered

• Do not rely on persistance that rely on DTC • share connection to prevent auto promotion

• If you use persistence that relies on local disk• Make sure it’s configured for failover or clustered

Page 34: NSBCon UK nservicebus on Azure by Yves Goeleven

Websites

Page 35: NSBCon UK nservicebus on Azure by Yves Goeleven

WebsitesShared website hosting

• IIS as a service

• With Continuous Integration built in• Deploy straight from github/bitbucket/tfs/...

• You only controle your code• Nothing else

Page 36: NSBCon UK nservicebus on Azure by Yves Goeleven

WebsitesNServiceBus self hosting can be used

• Only public remote transports can be used• Only public remote persistance can be used

• Remote: No option to install on the machine

• Public: No option to setup virtual networking with cloudservices or virtual machines

Page 37: NSBCon UK nservicebus on Azure by Yves Goeleven

Transports

Page 38: NSBCon UK nservicebus on Azure by Yves Goeleven

Best transportsBecause they retry and are built for failover

Azure ServiceBus

Azure Storage

Page 39: NSBCon UK nservicebus on Azure by Yves Goeleven

Optional transportsIf you manage it correctly (Failover, clustering, sharding, etc…)

Sql Database

DB DB

Sql Server Rabbit MQ Active MQ

Page 40: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure Storage QueuesQueue construct in Azure Storage Services

• Highly reliable• Very cheap• 200TB/500TB capacity limit• HTTP(S) based• Queue Peek Lock for retries• Max 7 days TTL!

Page 41: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure Storage QueuesConfigure NServiceBus to use azure storage queues

• Found in NServiceBus.Azure.Transports.WindowsAzureStorageQueues

• Connection string

• Detailed configuration

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureStorageQueues>{}

DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=myKey;

http://docs.particular.net/nservicebus/using-azure-storage-queues-as-transport-in-nservicebus

Page 42: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure ServiceBusBroker service in azure

• Reliable• Supports queues, topics & subscriptions• 5GB capacity limit• No limit on TTL• TCP based, lower latency• Queue Peek Lock for retries

• Emulates local transactions

• Loads of additional features• Dedupe, sessions, partitioning, ...

• Relatively expensive

Page 43: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure ServiceBusConfigure NServiceBus to use azure servicebus

• Found in NServiceBus.Azure.Transports.WindowsAzureServiceBus

• Connection string

• Detailed configuration

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureServiceBus>{}

http://docs.particular.net/nservicebus/using-azure-servicebus-as-transport-in-nservicebus

Endpoint=sb://{yournamespace}.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue={yourkey}

Page 44: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure ServiceBusAdditional features & applicability

• Applicable• Duplicate detection: time window• Partitioning: Bundle of queues/topics• Message ordering• Deadlettering• Batched operations

• Not applicable:• Sessions: instance affinity for message set, used for large messages, use databus

instead

Page 45: NSBCon UK nservicebus on Azure by Yves Goeleven

Persistence

Page 46: NSBCon UK nservicebus on Azure by Yves Goeleven

Best persistenceBecause it is built for failover

Azure Storage

Page 47: NSBCon UK nservicebus on Azure by Yves Goeleven

Optional persistenceIf you manage it correctly (Failover, clustering, sharding, etc…)

Sql Database

DB DB

Sql ServerRaven Db

Page 48: NSBCon UK nservicebus on Azure by Yves Goeleven

Azure StorageFound in NServiceBus.Azure

• Uses Azure Table Storage & Azure Blob Storage• Supports Subscriptions, Saga’s, Timeouts & Databus

• Configured for local emulator by default, detailed configuration;

public class EnableStorage : INeedInitialization{ public void Init() { Configure.Instance .AzureSubscriptionStorage() .AzureSagaPersister() .UseAzureTimeoutPersister() .AzureDatabus(); }}

http://docs.particular.net/nservicebus/using-azure-servicebus-as-transport-in-nservicebus

Page 49: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricks || Q&A

Page 50: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricksLessons learned the hard way

• Do not develop with the emulator (Compute nor storage)• Slow & behaves differently• Use nservicebus.hosting.azure.hostprocess for your workers• Use IISExpress for your websites• Use azure storage or azure servicebus online

Page 51: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricksLessons learned the hard way

• Deploy asap• Your machine != huge cloud• Test as if ‘in production’

Page 52: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricksLessons learned the hard way

• Tune the machine for lot’s of small requests

System.Net.ServicePointManager.DefaultConnectionLimit = 5000;System.Net.ServicePointManager.UseNagleAlgorithm = false;System.Net.ServicePointManager.Expect100Continue = false;

Page 53: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricksLessons learned the hard way

• Intellitrace is your best friend for remote debugging

Page 54: NSBCon UK nservicebus on Azure by Yves Goeleven

Tips & tricksLessons learned the hard way

• Log file shipping instead of default trace logs• Ship eventlog & log files via diagnostics service• Configured in .wadcfg file• Trace logs in table storage is to unfriendly

Page 55: NSBCon UK nservicebus on Azure by Yves Goeleven

Wrapup

Page 56: NSBCon UK nservicebus on Azure by Yves Goeleven

Want to know more?

• Overview: http://docs.particular.net/nservicebus/windows-azure-transport• Hosting: http://docs.particular.net/nservicebus/hosting-nservicebus-in-windows-azure• Cloud services: http://docs.particular.net/nservicebus/hosting-nservicebus-in-windows-azure-cloud-services• Shared host: http://docs.particular.net/nservicebus/shared-hosting-nservicebus-in-windows-azure-cloud-services• Azure servicebus: http://docs.particular.net/nservicebus/using-azure-servicebus-as-transport-in-nservicebus• Azure storage queues: http://

docs.particular.net/nservicebus/using-azure-storage-queues-as-transport-in-nservicebus• Storage persistence: http://docs.particular.net/nservicebus/using-azure-storage-persistence-in-nservicebus• Transactions: http://docs.particular.net/nservicebus/understanding-transactions-in-windows-azure

Resources

Page 57: NSBCon UK nservicebus on Azure by Yves Goeleven

Or get your hands dirty?

• Samples: https://github.com/particular/nservicebus.azure.samples

Resources

Page 58: NSBCon UK nservicebus on Azure by Yves Goeleven

Thanks