Azure Cloud Services Host Upgrade Version 6 to 7

Namespace changes

All types specified in this document are now in the NServiceBus namespace.

IConfigureThisEndpoint changes

IConfigureThisEndpoint.Customize is passed an instance of EndpointConfiguration instead of BusConfiguration.

7.x NServiceBus.Hosting.Azure
public class EndpointConfig :
    IConfigureThisEndpoint,
    AsA_Worker
{
    public void Customize(EndpointConfiguration endpointConfiguration)
    {
        var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
        transport.ConnectionString("Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]");
        endpointConfiguration.UsePersistence<AzureStoragePersistence>();
    }
}
6.x NServiceBus.Hosting.Azure
public class EndpointConfig :
    IConfigureThisEndpoint,
    AsA_Worker
{
    public void Customize(BusConfiguration busConfiguration)
    {
        var transport = busConfiguration.UseTransport<AzureServiceBusTransport>();
        transport.ConnectionString("Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]");
        busConfiguration.UsePersistence<AzureStoragePersistence>();
    }
}

AsA_Host role changes into IConfigureThisHost

The specifiers IConfigureThisEndpoint and AsA_Host are now merged into IConfigureThisHost.

7.x NServiceBus.Hosting.Azure
public class EndpointHostConfig :
    IConfigureThisHost
{
    public HostingSettings Configure()
    {
        return new HostingSettings("DefaultEndpointsProtocol=https;AccountName=[ACCOUNT];AccountKey=[KEY];");
    }
}
6.x NServiceBus.Hosting.Azure
public class EndpointHostConfig :
    IConfigureThisEndpoint,
    AsA_Host
{
    public void Customize(BusConfiguration configuration)
    {

    }
}

Removal of DynamicHostControllerConfig

The DynamicHostControllerConfigconfiguration section has been removed, instead the IConfigureThisHost.Customize implementation requires to return an instance of HostSettings which contains all the configuration values.

RoleEnvironment.GetConfigurationSettingValue can be used to read any existing configuration setting from the .cscfg file.

Removal of dependencies

The host role entry point and host process no longer depend on the following components.

  • Log4Net
  • Ionic.zip
  • Topshelf
  • CommonServiceLocator

If these components are not used for other purposes they may be removed.

Deprecation of profiles

The infrastructure backing profiles has been removed from the host and therefore the Development and Production profiles are no longer available. Note that Visual Studio native logging has replaced the profiles. Refer to the logging documentation to learn how to set this up.

Any code in custom profile handlers should be moved into the IConfigureThisEndpoint or IConfigureThisHost configuration extension points.

IWantToRunWhenEndpointStartsAndStops

An interface IWantToRunWhenEndpointStartsAndStops has been added. This interface replaces the IWantToRunWhenBusStartsAndStops in the NServiceBus core.

Interface in Version 5 of NServiceBus

5.x NServiceBus
public class Bootstrapper :
    IWantToRunWhenBusStartsAndStops
{
    public void Start()
    {
        // Do startup actions here.
    }

    public void Stop()
    {
        // Do cleanup actions here.
    }
}

Interface in Version 7 of NServiceBus.Hosting.Azure

7.x NServiceBus.Hosting.Azure
namespace CloudServicesHost_7.Core5to6
{
    public class Bootstrapper :
        IWantToRunWhenEndpointStartsAndStops
    {
        public Task Start(IMessageSession session)
        {
            // Do startup actions here.
            // Either mark Start method as async or do the following
            return Task.CompletedTask;
        }

        public Task Stop(IMessageSession session)
        {
            // Do cleanup actions here.
            // Either mark Stop method as async or do the following
            return Task.CompletedTask;
        }
    }
}

Related Articles


Last modified