CreateRule exception

Hi
We have starting to receive the following exception in our logs.

sbt-adp-adapter-incoming/Subscriptions/nsb-sub-avonovaAdapter-35acba06-1835-4dea-89a5-88d4107419f1: CreateRule Exception: Azure.Messaging.ServiceBus.ServiceBusException: The messaging entity 'sb-adp-westeurope-prod:Topic:sbt-adp-adapter-incoming|nsb-sub-avonovaadapter|Adp.Common.Messages.Mds.ReceiveMessageMdsCompany' already exists. To know more visit https://aka.ms/sbResourceMgrExceptions.  TrackingId:7e7ac61f-3e7f-4920-bbf7-004242148300_B14, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 Reference:e23d7c27-199c-495f-92ad-ad49cec2d65c, TrackingId:2cc0489a-0556-4d37-982f-41170123d009_G22, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 (MessagingEntityAlreadyExists). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.
   at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.AddRuleInternalAsync(RuleProperties description, TimeSpan timeout)
   at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.<>c.<<CreateRuleAsync>b__8_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<>c__22`1.<<RunOperation>b__22_0>d.MoveNext()
--- End of stack trace from previous location ---
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose)
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose)
   at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.CreateRuleAsync(RuleProperties properties, CancellationToken cancellationToken)
   at Azure.Messaging.ServiceBus.ServiceBusRuleManager.CreateRuleAsync(CreateRuleOptions options, CancellationToken cancellationToken). RuleName = Adp.Common.Messages.Mds.ReceiveMessageMdsCompany

This exception occurs when our function app receives a Service bus message in our implementation of the IMessageHandler (see start of code below).

Does NServicebus try to add a filter rule to the topic ?

Here is some traces from application insight that hints me that this initiated by NServiceBus

11/29/2023, 1:37:26 PM
-
Trace
Executing 'NServiceBusFunctionEndpointTrigger-nsb-sub-avonovaAdapter' (Reason='(null)', Id=cf36c430-1dcd-4a6d-bfb8-88b729b42056)
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:26 PM
-
Trace
Trigger Details: MessageId: 3a36a7d7-c285-48e6-9a3f-0b4bd3410ac3, SequenceNumber: 1013424, DeliveryCount: 1, EnqueuedTimeUtc: 2023-11-29T12:37:26.4700000+00:00, LockedUntilUtc: 2023-11-29T12:38:26.4700000+00:00, SessionId: (null)
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:26 PM
-
Trace
No valid license could be found. Falling back to trial license with start date '2023-11-29'.
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:26 PM
-
Trace
Auditing processed messages to 'nsb-sbq-audit'
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:27 PM
-
Trace
sbt-adp-adapter-incoming/Subscriptions/nsb-sub-avonovaAdapter-35acba06-1835-4dea-89a5-88d4107419f1: CreateRule Exception: Azure.Messaging.ServiceBus.ServiceBusException: The messaging entity 'sb-adp-westeurope-prod:Topic:sbt-adp-adapter-incoming|nsb-sub-avonovaadapter|Adp.Common.Messages.Mds.ReceiveMessageMdsPerson' already exists. To know more visit https://aka.ms/sbResourceMgrExceptions. TrackingId:d2af9b10-7b3a-45e4-8e88-632d83e77670_B14, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 Reference:917a4bd9-223c-4cf7-84af-ffa4275e454e, TrackingId:cdea97b2-03a4-4b0d-a8a4-cfe1c4d50cd4_G22, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 (MessagingEntityAlreadyExists). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot. at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.AddRuleInternalAsync(RuleProperties description, TimeSpan timeout) at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.<>c.<<CreateRuleAsync>b__8_0>d.MoveNext() --- End of stack trace from previous location --- at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<>c__22`1.<<RunOperation>b__22_0>d.MoveNext() --- End of stack trace from previous location --- at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose) at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose) at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.CreateRuleAsync(RuleProperties properties, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.ServiceBusRuleManager.CreateRuleAsync(CreateRuleOptions options, CancellationToken cancellationToken). RuleName = Adp.Common.Messages.Mds.ReceiveMessageMdsPerson
Severity level: ErrorParent Id: c855c800fa83fe57
11/29/2023, 1:37:27 PM
-
Trace
sbt-adp-adapter-incoming/Subscriptions/nsb-sub-avonovaAdapter-35acba06-1835-4dea-89a5-88d4107419f1: CreateRule Exception: Azure.Messaging.ServiceBus.ServiceBusException: The messaging entity 'sb-adp-westeurope-prod:Topic:sbt-adp-adapter-incoming|nsb-sub-avonovaadapter|Adp.Common.Messages.Mds.ReceiveMessageMdsCompany' already exists. To know more visit https://aka.ms/sbResourceMgrExceptions. TrackingId:7e7ac61f-3e7f-4920-bbf7-004242148300_B14, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 Reference:e23d7c27-199c-495f-92ad-ad49cec2d65c, TrackingId:2cc0489a-0556-4d37-982f-41170123d009_G22, SystemTracker:NoSystemTracker, Timestamp:2023-11-29T12:37:27 (MessagingEntityAlreadyExists). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot. at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.AddRuleInternalAsync(RuleProperties description, TimeSpan timeout) at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.<>c.<<CreateRuleAsync>b__8_0>d.MoveNext() --- End of stack trace from previous location --- at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<>c__22`1.<<RunOperation>b__22_0>d.MoveNext() --- End of stack trace from previous location --- at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose) at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken, Boolean logTimeoutRetriesAsVerbose) at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.Amqp.AmqpRuleManager.CreateRuleAsync(RuleProperties properties, CancellationToken cancellationToken) at Azure.Messaging.ServiceBus.ServiceBusRuleManager.CreateRuleAsync(CreateRuleOptions options, CancellationToken cancellationToken). RuleName = Adp.Common.Messages.Mds.ReceiveMessageMdsCompany
Severity level: ErrorParent Id: c855c800fa83fe57
11/29/2023, 1:37:27 PM
-
Trace
Handling ReceiveMessageMdsPerson, MessageId: 65be7af420014f3d846b1943b6ab8a02, contextId: 21b329b3-9bef-41dd-add0-b0c900d0097f, HandleMessage, F:\Agents\_work\12\s\Src\Adp.Adapter.AvonovaDigital\MessageHandlers\ReceiveMessageMdsHandler.cs, 54
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:27 PM
-
Trace
OriginalSource is AvonovaDigital, HandleMessage, F:\Agents\_work\12\s\Src\Adp.Adapter.AvonovaDigital\MessageHandlers\ReceiveMessageMdsHandler.cs, 66
Severity level: InformationParent Id: c855c800fa83fe57
11/29/2023, 1:37:28 PM
-
Trace
Executed 'NServiceBusFunctionEndpointTrigger-nsb-sub-avonovaAdapter' (Succeeded, Id=cf36c430-1dcd-4a6d-bfb8-88b729b42056, Duration=1470ms)
Severity level: InformationParent Id: c855c800fa83fe57

And here is part of our IMessageHandler implementation

public class ReceiveMessageMdsHandler :
    IHandleMessages<ReceiveMessageMdsCompany>,
    IHandleMessages<ReceiveMessageMdsPerson>
{
    private readonly IMediator _mediator;
    private readonly ILogger _logger;
    private readonly IFeatureFlags _featureFlags;

    public ReceiveMessageMdsHandler(IMediator mediator, ILogger<ReceiveMessageMdsHandler> logger, IFeatureFlags featureFlags)
    {
        _mediator = mediator;
        _logger = logger;
        _featureFlags = featureFlags;
    }

    public async Task Handle(ReceiveMessageMdsCompany message, IMessageHandlerContext context)
    {
        await HandleMessage<Company>(message, context);
        await context.Reply(new PublishSuccessAvonovaDigitalCompany());
    }

    public async Task Handle(ReceiveMessageMdsPerson message, IMessageHandlerContext context)
    {
        await HandleMessage<Person>(message, context);
        await context.Reply(new PublishSuccessAvonovaDigitalPerson());
    }

    private async Task HandleMessage<T>(IReceiveMdsMessage<T> message, IMessageHandlerContext context)
        where T : BaseDto
    {
        _logger.LogExtInfo($"Handling {message.GetType().Name}, MessageId: {message.MessageId}, contextId: {context.MessageId}");

        var adpMessage = message.AdpMessage;

We are using the following NServiceBus components
NServiceBus.AzureFunctions.InProcess.ServiceBus 4.2.0
NServiceBus.Transport.AzureServiceBus 3.2.1

Kind regards
Lars Kolsaker

Show how you configure the endpoint that’s hosted as Azure function.

Thanks for quick reply. Here is part of the Startup.cs that involves NServiceBus configuration

   public const string EndpointName = "nsb-sub-avonovaAdapter";
   
   private const string ErrorQueueName = "nsb-sbq-error";
   private const string AuditQueueName = "nsb-sbq-audit";
   private const string TopicName = "sbt-adp-adapter-incoming";

   public override void Configure(IFunctionsHostBuilder builder)
   {
       builder.Services.AddSingleton<IAvonovaDigitalCommonService, AvonovaDigitalCommonService>();
       builder.Services.AddSingleton<IAvonovaDigitalAdpService, AvonovaDigitalAdpService>();
       builder.Services.AddSingleton<IValidator, Validator>();
       builder.Services.AddSingleton<IRequestProcessor, RequestProcessor>();
       builder.Services.AddScoped<IUpserter, Upserter>();

       builder.Services.AddAutoMapper(typeof(DtoToAdProfile));

       builder.UseNServiceBus(nsbConfiguration =>
       {
           nsbConfiguration.Transport.Topology = TopicTopology.Single(TopicName);

           nsbConfiguration.AdvancedConfiguration.Recoverability()
               .Immediate(immediate =>
               {
                   immediate.NumberOfRetries(0);
               })
               .Delayed(delayed =>
               {
                   delayed.NumberOfRetries(5);
                   delayed.TimeIncrease(TimeSpan.FromSeconds(10));
               });

           nsbConfiguration.AdvancedConfiguration.SendFailedMessagesTo(ErrorQueueName);
           nsbConfiguration.AdvancedConfiguration.AuditProcessedMessagesTo(AuditQueueName);
           nsbConfiguration.AdvancedConfiguration.Recoverability().AddUnrecoverableException<UnrecoverableException>();
       });

NServiceBus.AzureFunctions.InProcess.ServiceBus should be the package you need, not NServiceBus.Transport.AzureServiceBus. It should not attempt to create the topology and provision entities. Could you remove the latter?

By removing NServiceBus.Transport.AzureServiceBus we get a compilation error on

nsbConfiguration.Transport.Topology = TopicTopology.Single(TopicName);

The name ‘TopicTopology’ does not exist in the current context

in startup.cs

You’re configuring the transport topology. This might be an issue if the transport assembly is picked up.
Raise an issue in GitHub?

Have raised an issue on Github