Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the...
-
date post
22-Dec-2015 -
Category
Documents
-
view
215 -
download
0
Transcript of Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the...
![Page 1: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/1.jpg)
Yves GoelevenCapgemini@YvesGoelevenhttp://cloudshaper.wordpress.com
Code D’Azure
Simplifying distributed applications with the Windows Azure Platform and NServiceBus
![Page 2: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/2.jpg)
Agenda
• Introduction• What is NServiceBus and why is it so
azurey?• Communication patterns• The basics of NServiceBus
development• Azure specific implementation details• Play Time
![Page 3: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/3.jpg)
What is a service bus ?
• An architectural pattern– Simplifies communication– Between services and their consumers
• Lousely coupled messaging– In space (contract)– And time (queues)
![Page 4: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/4.jpg)
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
![Page 5: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/5.jpg)
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
![Page 6: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/6.jpg)
NServiceBus Structure
Core
TimeoutManager
DynamicHost
...
...
Host
![Page 7: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/7.jpg)
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
![Page 8: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/8.jpg)
Agenda
• Introduction• What is NServiceBus and why is it so
azurey?• Communication patterns• Azure specific implementation details• The basics of NServiceBus
development• Play Time
![Page 9: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/9.jpg)
Moderatly Opinionated...
• 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
![Page 10: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/10.jpg)
One-way (Send)
Worker
Worker
Worker
Client
Client
Client
Queue
![Page 11: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/11.jpg)
Full Duplex (Send / Reply)
Worker
Worker
Worker
Client
Client
Client
Queue
Queue
![Page 12: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/12.jpg)
Pub / Sub (Publish)
Worker
Worker
Worker
Client
Client
Client
Queue
Queue
Queue
![Page 13: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/13.jpg)
Saga
Worker
Worker
Worker
Client
Client
Client
Queue
Queue
Queue
![Page 14: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/14.jpg)
DataBus
Worker
Worker
Worker
Client
Client
Client
Queue
FileStore
![Page 15: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/15.jpg)
Agenda
• Introduction• What is NServiceBus and why is it so
azurey?• Communication patterns• The basics of NServiceBus
development• Azure specific implementation details• Play Time
![Page 16: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/16.jpg)
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; } }
![Page 17: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/17.jpg)
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 } }
![Page 18: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/18.jpg)
• Using the IBus interface– Which is injected by the container
Send or publish messages
public class CreateLargeThumbnail : IHandleMessages<ImageUploaded> { private readonly IBus Bus;
public void Handle(ImageUploaded message) { // create a large thumbnail
bus.Publish(new ThumbNailCreated()); } }
![Page 19: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/19.jpg)
• Message to endpoint mapping in config
Message Routing
<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>
![Page 20: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/20.jpg)
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
![Page 21: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/21.jpg)
Compose the bus as you like...
• Configure – What you need is defined in code– Details are defined either in config or
codeConfigure.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
![Page 22: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/22.jpg)
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(); }}
![Page 23: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/23.jpg)
Agenda
• Introduction• What is NServiceBus and why is it so
azurey?• Communication patterns• The basics of NServiceBus
development• Azure specific implementation details• Play Time
![Page 24: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/24.jpg)
Configuration
• AzureConfigurationsource()– Uses config section from app.config – And overrides settings from service
configuration file
• Override by convention– <Key Attribute=“value”>– Key.Attribute=“value”
![Page 25: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/25.jpg)
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.ScheduledTransfer
Period– Microsoft.WindowsAzure.Plugins.Diagnostics.EventLogs
![Page 26: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/26.jpg)
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
![Page 27: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/27.jpg)
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
![Page 28: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/28.jpg)
Subscription storage
• AzureSubcriptionStorage()– Uses Nhibernate over table storage
• ConfigurationSettings– AzureSubscriptionStorageConfig.ConnectionStri
ng– AzureSubscriptionStorageConfig.CreateSchema
![Page 29: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/29.jpg)
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>
![Page 30: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/30.jpg)
Saga storage
• .Sagas().AzureSagaPersister().NHibernateUnitOfWork()– Uses Nhibernate over table storage
• ConfigurationSettings– AzureSagaPersisterConfig.ConnectionString– AzureSagaPersisterConfig.CreateSchema
![Page 31: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/31.jpg)
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>
![Page 32: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/32.jpg)
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
![Page 33: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/33.jpg)
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
![Page 34: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/34.jpg)
Hosting
• Generic Roles– AsA_Listener– AsA_Worker
• Specific Roles– AsA_Host– AsA_TimeoutManager
![Page 35: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/35.jpg)
Hosting
• Environment Profiles– Development– Production
• Storage Profiles– OnAzureTableStorage– OnSqlAzure
• Communication Profiles– WithAzureStorageQueues– WithAppFabricQueues
![Page 36: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/36.jpg)
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
![Page 37: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/37.jpg)
Agenda
• Introduction• What is NServiceBus and why is it so
azurey?• Communication patterns• The basics of NServiceBus
development• Azure specific implementation details• Play Time
![Page 38: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/38.jpg)
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
![Page 39: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/39.jpg)
Architecture
Worker
Worker
Website
Website
Queue
DataBus
Queue
Queue
Worker
Worker
Queue
Upload image
Photo processing: - Store original- Create thumbnails
Sharing: - Upd. photostream
Notify User & Clear caches
SubscriptionsSaga’s
Worker
WorkerQueue
Timeout Manager
![Page 40: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/40.jpg)
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
![Page 41: Yves Goeleven Capgemini @YvesGoeleven Code D’Azure Simplifying distributed applications with the Windows Azure Platform.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d795503460f94a5cc68/html5/thumbnails/41.jpg)
Yves GoelevenCapgemini@YvesGoelevenhttp://cloudshaper.wordpress.com
Questions?