Azure functions do not work with Azure Service Bus topics

Antonio Andrés Avila Moreno 5 Reputation points
2023-05-02T16:58:22.16+00:00

I create an Azure Function of type Service Bus with theme, from Visual Studio 2022 Community Edition using C#, I configure the connection with a full permissions endpoint.

When trying to do debugging, it doesn't do anything and in the output window, after loading the symbols, sometimes it just puts an error, but other times it doesn't put anything.

The service bus contains at least 5 messages with 2 subscriptions, one with the session enabled and the other with the session disabled.

The error that sometimes gets displayed in the output window is:

Exception thrown: 'Azure.RequestFailedException' in System.Private.CoreLib.dll

I have used both the libraries with the version that the project is created (Microsoft.NET.Sdk.Functions 4.1.1 and Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.3.0), even using the latest versions of these components (Microsoft. NET.Sdk.Functions 4.2.0 and Microsoft.Azure.WebJobs.Extensions.ServiceBus 5.9.0)

This happens to me both with subscriptions with the session option enabled or disabled.

Functions

DebugFunction

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
649 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,190 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

  2. MuthuKumaranMurugaachari-MSFT 22,361 Reputation points
    2023-05-03T15:49:37.0066667+00:00

    Antonio Andrés Avila Moreno Thanks for posting your question in Microsoft Q&A. Based on your description, you face this issue with .NET 6, however .NET 3.1 works fine. Can you confirm if you have Connection string with secret or using Identify based connections? (Since you have tested in Postman, I guess it is likely secret).

    Here is my local test which works fine without any errors and you can try with the same.

    .csproj

    User's image

    local.settings.json

    User's image

    Program.cs

    public class Function1
        {
            private readonly ILogger<Function1> _logger;
    
            public Function1(ILogger<Function1> log)
            {
                _logger = log;
            }
    
            [FunctionName("Function1")]
            public void Run([ServiceBusTrigger("mtopic", "msubscription", Connection = "MSBCONNECTION")]string mySbMsg)
            {
                _logger.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
            }
        }
    

    mtopic - my topic name

    msubscription - my subscription in mtopic

    MSBCONNECTION - connection string with secret for SB namespace (not topic or queue) as suggested in doc: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?pivots=programming-language-csharp&tabs=python-v2%2Cin-process%2Cextensionv5#connection-string

    If you still face the issue, share local.settings.json (hiding connection string), full .csproj reference, that will help in reproducing the issue. I hope this helps and let me know if you still face the issues.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.