Naming Conventions

This page refers to the legacy Azure Service Bus transport, which is rendered obsolete by the Azure Service Bus transport built to target both .NET Framework and .NET Core. All new projects should use the new Azure Service Bus transport.

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