1 / 41

Code D’Azure

Simplifying distributed applications with the Windows Azure Platform and NServiceBus. Code D’Azure. Agenda. Introduction What is NServiceBus and why is it so azurey? Communication patterns The basics of NServiceBus development Azure specific implementation details Play Time.

glynn
Télécharger la présentation

Code D’Azure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simplifying distributed applications with the Windows Azure Platform and NServiceBus Code D’Azure

  2. Agenda • Introduction • What is NServiceBus and why is it so azurey? • Communication patterns • The basics of NServiceBus development • Azure specific implementation details • Play Time

  3. What is a service bus ? • An architectural pattern • Simplifies communication • Between services and their consumers • Lousely coupled messaging • In space (contract) • And time (queues)

  4. Still, a lot of distractions... • Distributed application development is not that easy • Multithreaded message handling, addressing & routing, transaction scoping, correlation, message header management, serialization & version tolerance, subscription management, persisting state of long running communication, timeouts, … • All distractions from what really matters: The business logic

  5. What is NServiceBus? • A logical service bus • A framework to support this architectural pattern • Abstract underlying infrastructure (queues, broker) • Ambitions • Make development of scalable, distributed apps SIMPEL • So that developers can focus on their business domain & logic

  6. NServiceBusStructure Host Core ... DynamicHost TimeoutManager ...

  7. Why is it so azurey? • We share a common goal (but at a different level) • Make it easy to build scalable distributed apps • Azure provides all primitives NServiceBus needs • Durable queues: Storage, AppFabric • Storage: Table, Relational, Blob

  8. Agenda • Introduction • What is NServiceBus and why is it so azurey? • Communication patterns • Azure specific implementation details • The basics of NServiceBus development • Play Time

  9. ModeratlyOpinionated... • Components are autonomous • Nothing shared : Own process, queue, data store, ... • Communication between components is • Message based : Asynchronous, Queued, Durable • Only a handful of patterns are supported • On purpose

  10. One-way (Send) Client Worker Client Worker Queue Client Worker

  11. Full Duplex (Send / Reply) Client Worker Queue Client Worker Queue Client Worker

  12. Pub / Sub (Publish) Client Worker Queue Client Worker Queue Client Worker Queue

  13. Saga Client Worker Queue Client Worker Queue Client Worker Queue

  14. DataBus Client Worker Client Worker Queue Client FileStore Worker

  15. Agenda • Introduction • What is NServiceBus and why is it so azurey? • Communication patterns • The basics of NServiceBus development • Azure specific implementation details • Play Time

  16. Define message contracts... • Implement IMessage • You can choose your own interface if you like • public class ImageUploaded : IMessage • { • public Guid Id { get; set; } • public string FileName { get; set; } • public string ContentType { get; set; } • public byte[] Image { get; set; } • }

  17. Handle messages • Implement IHandleMessages<T> • In any assembly referenced by a process that has a bus configured • public class CreateLargeThumbnail : IHandleMessages<ImageUploaded> • { • public void Handle(ImageUploaded message) • { • // do something • } • }

  18. Send or publish messages • Using the IBus interface • Which is injected by the container • public class CreateLargeThumbnail : IHandleMessages<ImageUploaded> • { • private readonlyIBusBus; • public void Handle(ImageUploaded message) • { • // create a large thumbnail • bus.Publish(new ThumbNailCreated()); • } • }

  19. Message Routing • Message to endpoint mapping in config • <configSections> • <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/> • </configSections> • <UnicastBusConfig> • <MessageEndpointMappings> • <add Messages="MyFlickr.WebSite.Events" Endpoint="processorinputqueue"/> • <add Messages="MyFlickr.Sharing.Events" Endpoint="sharinginputqueue"/> • </MessageEndpointMappings> • </UnicastBusConfig>

  20. The core is a skeleton... • With some default implementations • But everything is replaceable • By default • Msmq, Autofac, Log4net, Nhibernate/RavenDB • We will replace • By azure’s services

  21. Compose the bus as you like... • Configure • What you need is defined in code • Details are defined either in config or code • Configure.WithWeb() // assemblies to parse • .DefaultBuilder() // ioc container • .Log4Net(new AzureAppender()) // diagnostics • .AzureConfigurationSource() // configuration • .AzureMessageQueue() // queue infrastructure • .JsonSerializer() // serializer • .QueuePerInstance() // addressing behavior • .UnicastBus() // how the bus behaves • .LoadMessageHandlers() // loads messagehandlers • .IsTransactional(true) // transactional behavior • .CreateBus() // create an instance of the bus • .Start(); // start the instance

  22. Or use a predefined roles & profiles • Inherit from RoleEntryPoint • Configure the endpoint • Customize if required public class Host : NServiceBus.Hosting.Azure.RoleEntryPoint { } public class EndpointConfiguration : IConfigureThisEndpoint, AsA_Worker { } public class SetupDataBus : IWantCustomInitialization { public void Init() { Configure.Instance.AzureDataBus(); } }

  23. Agenda • Introduction • What is NServiceBus and why is it so azurey? • Communication patterns • The basics of NServiceBus development • Azure specific implementation details • Play Time

  24. Configuration • AzureConfigurationsource() • Uses configsection from app.config • And overrides settings from service configuration file • Override by convention • <Key Attribute=“value”> • Key.Attribute=“value”

  25. Diagnostics • Log4Net<AzureAppender>() • Directs output to diagnostics manager • Works with or without .wadcfg file • Configuration settings • Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString • Microsoft.WindowsAzure.Plugins.Diagnostics.Level • Microsoft.WindowsAzure.Plugins.Diagnostics.Layout • Microsoft.WindowsAzure.Plugins.Diagnostics.ScheduledTransferPeriod • Microsoft.WindowsAzure.Plugins.Diagnostics.EventLogs

  26. Queueing • AzureMessageQueue() • Uses azure storage queues as infrastructure • Semi-transactional (Peek-lock) • Back-off (Linear) • Batching • Shared or per instance • ConfigurationSettings • AzureQueueConfig.ConnectionString • AzureQueueConfig.MessageInvisibleTime ( x BatchSize ) • AzureQueueConfig.PeekInterval • AzureQueueConfig.MaximumWaitTimeWhenIdle • AzureQueueConfig.BatchSize • AzureQueueConfig.QueuePerInstance

  27. Queueing • AppFabricMessageQueue() • Uses appfabric queues as infrastructure • Semi-transactional (Peek-lock) • Shared or per instance • ConfigurationSettings • AppFabricQueueConfig.IssuerName • AppFabricQueueConfig.IssuerKey • AppFabricQueueConfig.ServiceNamespace • AppFabricQueueConfig.LockDuration • AppFabricQueueConfig.MaxSizeInMegabytes • AppFabricQueueConfig.RequiresDuplicateDetection • AppFabricQueueConfig.RequiresSession • AppFabricQueueConfig.DefaultMessageTimeToLive • AppFabricQueueConfig.EnableDeadLetteringOnMessageExpiration • AppFabricQueueConfig.DuplicateDetectionHistoryTimeWindow • AppFabricQueueConfig.MaxDeliveryCount • AppFabricQueueConfig.EnableBatchedOperations • AppFabricQueueConfig.QueuePerInstance

  28. Subscription storage • AzureSubcriptionStorage() • Uses Nhibernate over table storage • ConfigurationSettings • AzureSubscriptionStorageConfig.ConnectionString • AzureSubscriptionStorageConfig.CreateSchema

  29. Subscription storage • DBSubcriptionStorage() • Nhibernate with connectionstring to SQL Azure • <DBSubscriptionStorageConfig> • <NHibernateProperties> • <add Key="connection.provider" • Value="NHibernate.Connection.DriverConnectionProvider"/> • <add Key="connection.driver_class" • Value="NHibernate.Driver.SqlClientDriver"/> • <add Key="connection.connection_string" • Value="Server=tcp:{server}.database.windows.net; Database={database}; User ID={user}@{server}; Password={password}; • Trusted_Connection=False; • Encrypt=True;"/> • <add Key="dialect" Value="NHibernate.Dialect.MsSql2005Dialect"/> • </NHibernateProperties> • </DBSubscriptionStorageConfig>

  30. Saga storage • .Sagas().AzureSagaPersister().NHibernateUnitOfWork() • Uses Nhibernate over table storage • ConfigurationSettings • AzureSagaPersisterConfig.ConnectionString • AzureSagaPersisterConfig.CreateSchema

  31. Saga storage • .Sagas().NHibernateSagaPersister().NHibernateUnitOfWork() • With connectionstring to SQL Azure • <NHibernateSagaPersisterConfig> • <NHibernateProperties> • <add Key="connection.provider" • Value="NHibernate.Connection.DriverConnectionProvider"/> • <add Key="connection.driver_class" • Value="NHibernate.Driver.SqlClientDriver"/> • <add Key="connection.connection_string“ • Value="Server=tcp:{server}.database.windows.net; • Database={database}; • User ID={user}@{server}; • Password={password}; • Trusted_Connection=False; • Encrypt=True;"/> • <add Key="dialect" Value="NHibernate.Dialect.MsSql2005Dialect"/> • </NHibernateProperties> • </NHibernateSagaPersisterConfig>

  32. Databus • .AzureDataBus() • Large properties stored as files • Using block blobs in blob storage • Blocks uploaded in parallel • Including retry on failure • ConfigurationSettings • AzureDataBusConfig.ConnectionString • AzureDataBusConfig.MaxRetries • AzureDataBusConfig.BlockSize • AzureDataBusConfig.NumberOfIOThreads • AzureDataBusConfig.Container • AzureDataBusConfig. BasePath

  33. Hosting • 2 types of hosts • Role dedicated to an endpoint • Role hosts multiple endpoints in multiple processes • Both make sense • Limited features, lot’s of users -> Dedicated • Lot’s of features, limited users -> Shared

  34. Hosting • Generic Roles • AsA_Listener • AsA_Worker • Specific Roles • AsA_Host • AsA_TimeoutManager

  35. Hosting • Environment Profiles • Development • Production • Storage Profiles • OnAzureTableStorage • OnSqlAzure • Communication Profiles • WithAzureStorageQueues • WithAppFabricQueues

  36. Hosting • Shared hosting • RoleEntryPoint, configured AsA_Host • Will not start a bus • But will load other NServiceBus processes from blob storage • ConfigurationSettings • DynamicHostControllerConfig.ConnectionString • DynamicHostControllerConfig.Container • DynamicHostControllerConfig.LocalResource • DynamicHostControllerConfig.RecycleRoleOnError • DynamicHostControllerConfig.AutoUpdate • DynamicHostControllerConfig.UpdateInterval • DynamicHostControllerConfig.TimeToWaitUntilProcessIsKilled

  37. Agenda • Introduction • What is NServiceBus and why is it so azurey? • Communication patterns • The basics of NServiceBus development • Azure specific implementation details • Play Time

  38. Mision - Recreate Flickr • The basics of the app • User uploads photo • System stores it and creates thumbnails of different sizes: Original, Small, Medium, Large • System shares the photo with the world when all thumbnails have been created (Photostream, ...) • The system notifies the user and clears it’s caches

  39. Architecture • Sharing: • Upd. photostream Notify User & Clear caches Worker Subscriptions Website Queue Saga’s Queue Worker Queue Website Worker Queue Upload image Worker Timeout Manager DataBus Worker Queue Worker Photo processing: - Store original - Create thumbnails

  40. Getting started • Begin situation • https://goeleven.blob.core.windows.net/demos/nservicebus/Begin.zip • Code snippets can be found on • https://gist.github.com/1164912

  41. Questions?

More Related