5. Why people are interested in Azure?
Various reasons
• Automated,
• Scalability (scale out)
• Elasticity (scale in again)
• Cost
• Globally available
6. NServiceBus & Azure: Perfect match
All 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
7. What is Azure?
Global network of huge data centers operated by Microsoft
8.
9.
10. Some numbers
Just to illustrate how huge it is
• 13 regions
• 321 IP ranges
• 250.000+ customers
• 2.000.000+ VM’s
• 25+ trillion objects stored
12. Implications
Of such a huge network
• Latency is normal
• Machine failure is normal
• Network partitioning is normal
• No distributed transactions!
13. Implications
Of ‘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
14. How to deal with it
NServiceBus 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
15. How to deal with it
NServiceBus 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
16. How to deal with it
Do 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
20. Cloud services
Many identical vm’s managed by azure
• Stateless
• Based on a template (role)
• Includes agents
• Health reporting
• Diagnostics collection
• Runtime & configuration environment
27. Cloud services
Specific NServiceBus host
• Make use of agents present on the vm
• Runtime & configuration environment
• Diagnostics
• Found in NServiceBus.Hosting.Azure
28. Cloud services
Use 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();
}
}
29. Cloud services
And Configure your endpoint as a worker
• AsA_Worker: Specific profile, similar to AsA_Publisher on-premises but different defaults
public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureServiceBus>
{
}
• Configured for local emulator by default
• Don’t forget to change config settings before deploying to azure itself
30. Cloud services
Is designed for massive scale, what if you don’t need that
• AsA_Host: Specific profile for colocation
public class EndpointConfig : IConfigureThisEndpoint, AsA_Host
{
}
• 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)
32. Virtual Machines
Just 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
33. Virtual Machines
Regular 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
35. Websites
Shared website hosting
• IIS as a service
• With Continuous Integration built in
• Deploy straight from github/bitbucket/tfs/...
• You only controle your code
• Nothing else
36. Websites
NServiceBus 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
40. Azure Storage Queues
Queue 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!
41. Azure Storage Queues
Configure NServiceBus to use azure storage queues
• Found in NServiceBus.Azure.Transports.WindowsAzureStorageQueues
public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureStorageQueues>
{
}
• Connection string
DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=myKey;
• Detailed configuration
http://docs.particular.net/nservicebus/using-azure-storage-queues-as-transport-in-nservicebus
42. Azure ServiceBus
Broker 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
43. Azure ServiceBus
Configure NServiceBus to use azure servicebus
• Found in NServiceBus.Azure.Transports.WindowsAzureServiceBus
public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker, UsingTransport<AzureServiceBus>
{
}
• Connection string
Endpoint=sb://{yournamespace}.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue={yourkey}
• Detailed configuration
http://docs.particular.net/nservicebus/using-azure-servicebus-as-transport-in-nservicebus
44. Azure ServiceBus
Additional 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
50. Tips & tricks
Lessons 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
51. Tips & tricks
Lessons learned the hard way
• Deploy asap
• Your machine != huge cloud
• Test as if ‘in production’
52. Tips & tricks
Lessons 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;
53. Tips & tricks
Lessons learned the hard way
• Intellitrace is your best friend for remote debugging
54. Tips & tricks
Lessons 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