Condividi tramite


Creating a Custom Service Information Store

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

The Autoscaling Application Block includes two service information store implementations that you can select from in the block configuration: an XML service information store in Microsoft Azure blob storage and an XML service information store on the local file system. The first is intended for use when you host the block in Azure, the second when you host the block on-premises. Both share the same XML schema.

You can create your own custom service information store, for example to store the service information in a SQL Server database. In this scenario, both the location of the store and the format of the stored service information would differ from the two existing service information store implementations.

A custom service information store implementation must implement the IServiceInformationStore interface, as shown in the following code sample.

namespace Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling.ServiceModel
{
    using System;
    using System.Collections.Generic;

    public interface IServiceInformationStore
    {
        event EventHandler<EventArgs> StoreChanged;

        Role GetRole(string alias);

        IEnumerable<string> GetRoleAliases();

        ScaleGroup GetScaleGroup(string name);

        Queue GetQueue(string alias);

        StabilizerConfiguration GetStabilizerConfiguration();
    }
}

You should notify the block whenever the content of your service information store changes by using the StoreChanged event so that the block can load the new service information. The GetRoleAliases method returns a list of the aliases of the roles in the application that the block can scale, the GetRole method returns a named Role instance, the GetScaleGroup method returns a named ScaleGroup instance, the GetQueue method returns a named Queue instance, and the GetGlobalCooldownSettings method returns a CooldownSettings instance.

Note

The block treats the service information store as a read-only store. If you want to provide a mechanism for editing the service information in your store through code, you need to design and implement this functionality yourself.

If you want to pass custom configuration parameters to your custom service information store, your custom service information store class should have a constructor that takes a single parameter of type NameValueCollection, as shown in the following code sample. Note the use of the ConfigurationElementType attribute to decorate the class.

[ConfigurationElementType(typeof(CustomServiceInformationStoreData))]
public class CustomServiceInformationStore : IServiceInformationStore
{
    public CustomServiceInformationStore (NameValueCollection attributes)
    {
        ...
    }

    public event EventHandler<EventArgs> StoreChanged
    {
        ...
    }

    public Role GetRole(string alias)
    {
        ...
    }

    public IEnumerable<string> GetRoleAliases()
    {
        ...
    }

    public ScaleGroup GetScaleGroup(string name)
    {
        ...
    }

    public Queue GetQueue(string alias)
    {
        ...
    }

    public StabilizerConfiguration GetStabilizerConfiguration()
    {
        ...
    }
}

You must deploy the assembly that implements your custom service information store with the Autoscaling Application Block.

You must tell the Autoscaling Application Block about your custom service information store by using the Enterprise Library configuration tool. The following procedure shows how to configure the block to use a custom service information store.

Configuring the Autoscaling Application Block to use a custom service information store

  1. To change the service information store implementation to use a custom service information store, click the plus sign icon at the top right of the Service Information Store panel and then click Set Service Information Store.

    Follow link to expand image

  2. To store your rules in a custom service information store, click Use Custom Service Information Store, and then click Yes to confirm the change. Use the Type Name box to identify the type of your custom service information store implementation.

    Hh680884.7CBE7917F8BD64594F462F63B866E9DA(en-us,PandP.50).png

  3. You can provide any additional configuration data that your custom service information store requires by adding attributes. Each attribute is a key/value pair. The block passes all the key/value pairs to the constructor of your custom service information store class.

    Hh680884.54C571C3B1BAB238F06E2C0F3E71059F(en-us,PandP.50).png

Next Topic | Previous Topic | Home

Last built: June 7, 2012