Naming Conventions

Component: Azure Service Bus Transport
NuGet NServiceBus.Azure.Transports.WindowsAzureServiceBus (6.x)
Target NServiceBus Version: 5.x

Versions 6 and below

Naming Conventions

To have a fine-grained control over entity names generated by the ASB transport, NamingConventions class exposes several conventions that can be overwritten to provide customization.

Entity sanitization:

6.4 NServiceBus.Azure.Transports.WindowsAzureServiceBus
NamingConventions.EntitySanitizationConvention = (entityName, entityType) =>
{
    if (entityType == EntityType.Queue || entityType == EntityType.Topic)
    {
        var regexQueueAndTopicValidCharacters = new Regex(@"[^a-zA-Z0-9\-\._\/]");
        var regexLeadingAndTrailingForwardSlashes = new Regex(@"^\/|\/$");

        var result = regexQueueAndTopicValidCharacters.Replace(entityName, "");
        return regexLeadingAndTrailingForwardSlashes.Replace(result, "");
    }

    // Subscription
    var regexSubscriptionValidCharacters = new Regex(@"[^a-zA-Z0-9\-\._]");
    return regexSubscriptionValidCharacters.Replace(entityName, "");
};

This sanitization allows forward slash / in queue and topic names unlike default sanitization convention used by Azure Service Bus transport.

Entities creation:

6.4 NServiceBus.Azure.Transports.WindowsAzureServiceBus
NamingConventions.QueueNamingConvention = (settings, messageType, queue, doNotIndividualize) =>
{
    return DetermineQueueNameUsingCustomLogic(settings, messageType, queue, doNotIndividualize);
};

NamingConventions.TopicNamingConvention = (settings, messageType, endpointName) =>
{
    return DetermineTopicNameUsingCustomLogic(settings, messageType, endpointName);
};

NamingConventions.SubscriptionNamingConvention = (settings, eventType, endpointName) =>
{
    return DetermineSubscriptionNameUsingCustomLogic(settings, eventType, endpointName);
};

NamingConventions.PublisherAddressConvention = (settings, address) =>
{
    return DeterminePublisherNameUsingCustomLogic(settings, address);
};

NamingConventions.QueueAddressConvention = (settings, address, doNotIndividualize) =>
{
    return DetermineQueueAddressUsingCustomLogic(settings, address, doNotIndividualize);
};

NamingConventions.PublisherAddressConvention = (settings, address) =>
{
    return DeterminePublisherAddressUsingCustomLogic(settings, address);
};
This is an advanced topic and requires full understanding of the topology.

Last modified