Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug ServiceBus-triggered Azure Function locally?

My function will be triggered from an existing ServiceBus topic. I have created the function using the new tooling in VS2017 (15.3) preview, as a compiled function.

How can I test this function locally?

like image 331
Alf Kåre Lefdal Avatar asked Aug 29 '17 09:08

Alf Kåre Lefdal


People also ask

How do I debug Azure function app locally?

Copy the settings file to the root of the Functions project next to the DLL, open a command prompt from there, and run “func start.” The Function will run based off the same trigger it would use if hosted in Azure or it can be manually triggered for testing using a local HTTP endpoint.

How do I debug Azure function locally in Visual Studio code?

In Visual Studio Code, press F5 to launch the debugger and attach to the Azure Functions host. You could also use the Debug > Start Debugging menu command. Output from the Functions Core tools appears in the Terminal panel.


2 Answers

For a non-http triggered function, you can send a POST request to the local administrator endpoint. More info here

like this (I am using Postman) enter image description here

like image 75
TomTichy Avatar answered Sep 29 '22 15:09

TomTichy


If you want to check whether your function will be triggered by Azure Service Bus messages, you need to own a Azure Subscription and create a Service Bus namespace because Microsoft haven't provided Azure Service Bus emulator like Azure Storage emulator.

If you want to debug your function, you could create a new console application and invoke the function you defined. Steps below are for your reference.

Step 1, Create a Console Application.

Step 2, Add Project reference to the function project.

Step 3, Install Microsoft.Azure.WebJobs -Version 2.1.0-beta1 package from NuGet to your console application.

Install-Package Microsoft.Azure.WebJobs -Version 2.1.0-beta1 

Step 4, Use following code to invoke your function.

class Program
{
    static void Main(string[] args)
    {
        Function1.Run("msg1", new MyTraceWriter(TraceLevel.Info));
    }
}

public class MyTraceWriter : TraceWriter
{
    public MyTraceWriter(TraceLevel level) : base(level)
    {

    }

    public override void Trace(TraceEvent traceEvent)
    {
        Console.WriteLine(traceEvent.Message);
    }
}
like image 40
Amor Avatar answered Sep 29 '22 13:09

Amor