ServiceStack.Azure package provides support to Azure ServiceBus and Azure Blob Storage. All features are incapsulated in single ServiceStack.Azure package. To install package run from NuGet
PM> Install-Package ServiceStack.Azure
ServiceStack.Azure includes implementation of the following ServiceStack providers:
- ServiceBusMqServer - MQ Server for invoking ServiceStack Services via Azure ServiceBus
- AzureBlobVirtualFiles - Virtual file system based on Azure Blob Storage
- AzureAppendBlobVirtualFiles - Virtual file system based on Azure Blob Storage for appending scenarios
- AzureTableCacheClient - Cache client over Azure Table Storage
The code to configure and start an ServiceBus MQ Server is similar to other MQ Servers:
container.Register<IMessageService>(c =>newServiceBusMqServer(ConnectionString));//prefetch defaults to 0 (Service Bus default) if not provided// var prefetchCount = 10;// container.Register<IMessageService>(c => new ServiceBusMqServer(ConnectionString));varmqServer=container.Resolve<IMessageService>();mqServer.RegisterHandler<ServiceDto>(ExecuteMessage,4);// 4 is the max concurrent calls (threads) mqServer.Start();Where ConnectionString is connection string to Service Bus, how to obtain it from Azure Portal you can find in Get Started with Service Bus queues article.
The prefetch account defaults to 0 and can be used to allow the clients to load additional messages from the service when it receives a read operation. You can find out more from Best Practices for performance improvements using Service Bus Messaging.
The number of thread parameter to the RegisterHandler gets or sets the maximum number of concurrent calls to the callback the message pump should initiate.
When an MQ Server is registered, ServiceStack automatically publishes Requests accepted on the "One Way" pre-defined route to the registered MQ broker. The message is later picked up and executed by a Message Handler on a background Thread.
You can use an Azure Blob Storage Container to serve website content with the AzureBlobVirtualFiles.
publicclassAppHost:AppHostBase{publicoverridevoidConfigure(Containercontainer){//All Razor Views, Markdown Content, imgs, js, css, etc are served from an Azure Blob Storage container//Use connection string to Azure Storage Emulator. For real application you should use connection string//to your Azure Storage accountvarazureBlobConnectionString="UseDevelopmentStorage=true";//Azure container which hold your files. If it does not exist it will be automatically created.varcontainerName="myazurecontainer";VirtualFiles=newAzureBlobVirtualFiles(connectionString,containerName);AddVirtualFileSources.Add(VirtualFiles);}}In addition you can use AzureAppendBlobVirtualFiles in scenarios that require appending such as logging.
publicclassAppHost:AppHostBase{publicoverridevoidConfigure(Containercontainer){Plugins.Add(newRequestLogsFeature{RequestLogger=newCsvRequestLogger(files:newAzureAppendBlobVirtualFiles(AppSettings.Get<string>("storageConnection"),"logfiles"),requestLogsPattern:"requestlogs/{year}-{month}/{year}-{month}-{day}.csv",errorLogsPattern:"requestlogs/{year}-{month}/{year}-{month}-{day}-errors.csv",appendEvery:TimeSpan.FromSeconds(30))});}}The AzureTableCacheClient implements ICacheClientExteded and IRemoveByPattern using Azure Table Storage.
publicclassAppHost:AppHostBase{publicoverridevoidConfigure(Containercontainer){stringcacheConnStr="UseDevelopmentStorage=true;";container.Register<ICacheClient>(newAzureTableCacheClient(cacheConnStr));}}