Azure Service Bus Failed to Receive error

I’m setting up a test app as my first use of NServiceBus (v9) with Azure Service Bus. It’s running as a Linux container on Azure Container Apps. The test app publishes a test event to a topic, and has a handler to consume the event which is just supposed to log a success message.

Publishing to the topic is working, but receiving is not and I’m getting the following error:

WARN Failed to receive a message on pump ‘Processor-Main-MyNamespace-1572b765-c93a-48c9-985b-2248d4bb7673’ listening on ‘MyNamespace’ connected to ‘asb-xxx.servicebus.windows.net’ due to ‘Receive’.

Exception: Azure.Messaging.ServiceBus.ServiceBusException: The messaging entity ‘asb-xxx:Topic:my-topic-name|amqps://asb-xxx.servicebus.windows.net/-cca565ad;9:14:59:source(address:/MyNamespace,filter:)’ could not be found.

The container app is configured to use a user-assigned identity, and that identity is in the Azure Service Bus Data Owner role.

The topic and the subscription do exist, so I’m not sure what messaging entity it’s not finding. It could perhaps be the address:/MyNamespace part as I’m not yet sure what that relates to.

Changing the endpoint name has fixed the issue. It was the same as my code namespace and differed only in case from my topic name. My guess is that the endpoint name must not be a case-insensitive duplicate of a topic name.

Hi @rick,

Thanks for sharing this. We will look into it.
I have raised this separately in this issue.
Feel free to subscribe if you want to track progress.

Something interesting to read could be this documentation that describes the topology.

Hi Rick,

There are a few documents that you might find helpful specifically related to Azure Service Bus.

This one describes how the topology is implemented and why. By default, there is a single topic topology.

Also, there is some general guidance for working with the Particular Software Platform in Azure

If you encounter any further problems, feel free to contact us here or by opening a non-critical support case.

@rick I have the same problem, Could you please elaborate more on how to fix it? This is my configuration and how to use them.

  "EventSettings": {
    "Events": {
      "TenantEvents": {
        "ConnectionString": "Endpoint=sb://<servicebusname>.servicebus.windows.net/;SharedAccessKeyName=SendPolicy;SharedAccessKey=<key>",
        "TopicName": "tenantevents"
      },
      "AcknowledgmentEvents": {
        "ConnectionString": "Endpoint=sb://<servicebusname>.servicebus.windows.net/;SharedAccessKeyName=send-and-recieve;SharedAccessKey=<key>",
        "TopicName": "acknowledgmentevents"
      }
    }
  }

This is how I access the consumer:

        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Starting EventAcknowledgmentConsumer...");

            var eventConfig = _eventSettings.Events["AcknowledgmentEvents"];
            _client = new ServiceBusClient(eventConfig.ConnectionString);
            _receiver = _client.CreateReceiver(eventConfig.TopicName);

            _logger.LogInformation("EventAcknowledgmentConsumer configured with Topic: {TopicName}", eventConfig.TopicName);

            // Start receiving messages
            await ReceiveMessagesAsync(cancellationToken);

            _logger.LogInformation("EventAcknowledgmentConsumer started.");
        }

This is how I published the event (publishing events are working fine):

app.MapPost("/events/publish", async (IEventPublisher eventPublisher, EventDto eventDto) =>
{
    var eventAcknowledgment = new EventAcknowledgment(eventDto.EventId, eventDto.ConsumerId, Enum.Parse<EventAcknowledgment.AcknowledgmentStatus>(eventDto.Status))
    {
        Timestamp = eventDto.Timestamp
    };
    await eventPublisher.PublishAsync(eventAcknowledgment);
    return Results.Ok(new { Message = "Event published successfully", EventId = eventAcknowledgment.EventId });
});


        public async Task PublishAsync<TEvent>(TEvent @event)
        {
            var eventConfig = GetEventConfig(@event);

            await using var client = new ServiceBusClient(eventConfig.ConnectionString);
            var sender = client.CreateSender(eventConfig.TopicName);

            var message = new ServiceBusMessage(JsonSerializer.Serialize(@event))
            {
                ContentType = "application/json",
                SessionId = Guid.NewGuid().ToString() // Set a unique SessionId
            };

            await sender.SendMessageAsync(message);
        }

        private EventConfig GetEventConfig<TEvent>(TEvent @event)
        {
            return @event switch
            {
                TenantCreatedEvent => _eventSettings.Events["TenantEvents"],
                TenantUpdatedEvent => _eventSettings.Events["TenantEvents"],
                TenantDeletedEvent => _eventSettings.Events["TenantEvents"],
                EventAcknowledgment => _eventSettings.Events["AcknowledgmentEvents"],
                // Add other event types and their corresponding configurations here
                _ => throw new ArgumentOutOfRangeException(nameof(@event), @event, null)
            };
        }
    }

When a consumer registers, I can see these logs, but when trying to consume the messages, it is saying cannot find the topic.

2025-03-03 06:34:54       Azure.Messaging.ServiceBus.ServiceBusException: The messaging entity '<servicebusname>:topic:acknowledgmentevents~15|amqps://<servicebusname>.servicebus.windows.net/-a46a10d0;0:5:6:source(address:/acknowledgmentevents,filter:[])' could not be found. To know more visit https://aka.ms/sbResourceMgrExceptions.  TrackingId:bcdbc70c-95ea-47b7-aabd-e6aa3db58423_B6, SystemTracker:gi::G7:Recv:1646104:638765501148700000:<servicebusname>:topic:acknowledgmentevents~15:F0:C11, bi::in-connection2278(G7-1156480)::session2286::link10087117, Timestamp:2025-03-03T05:34:54 TrackingId:fb67cf36800149079d2f511a4d83f734_G7, SystemTracker:gateway10, Timestamp:2025-03-03T05:34:54 (MessagingEntityNotFound). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.
2025-03-03 06:34:54          at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsyncInternal(Int32 maxMessages, Nullable`1 maxWaitTime, TimeSpan timeout, CancellationToken cancellationToken)
2025-03-03 06:34:54          at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<>c.<<ReceiveMessagesAsync>b__44_0>d.MoveNext()

@DilankaM In our case the solution was to make the endpoint name and the topic name different. By endpoint name I mean the value passed to

new EndpointConfiguration(endpointName)

and by topic name I mean the value passed to:

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
transport.TopicName(EndpointConstants.Topics.SchemeValuations);

They have to differ by more than just case.

I’ve also seen a very similar error on a send-only endpoint that didn’t have a queue created for it. It’s never going to receive anything from that queue but it wants it to exist anyway.