Search code examples
c#azuremqtt

The link address '$management' did not match any of the expected formats


I'm trying to build a function that will listen to the incoming MQTT messages in my Azure IoT hub.

I'm clueless why I keep getting errors and I'm not sure what I'm missing, I just have the base code as I just wanted to test if it would reach the breakpoint and if there was indeed a message.

So, my code is the following: Function1.cs

public static class Function1
{

    private static HttpClient client = new HttpClient();

    [FunctionName("Function1")]
    public static void Run([IoTHubTrigger("messages/events", Connection = "connectionString", ConsumerGroup = "FuncGroup")]EventData message, ILogger log)
    {
        string hello = "hey";
        log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.ToArray())}");
    }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "connectionString": "Endpoint=sb://[hub url].azure-devices.net/;SharedAccessKeyName=[username];SharedAccessKey=[password];"
  }
}

When I run the function I get always the same error:

The listener for function 'Function1' was unable to start. System.Private.CoreLib: One or more errors occurred. (The link address '$management' did not match any of the expected formats. (messages/events)) (The link address '$management' did not match any of the expected formats. (messages/events)). System.Private.CoreLib: The link address '$management' did not match any of the expected formats. (messages/events). System.Private.CoreLib: The link address '$management' did not match any of the expected formats.

I have also tried to add the EntityPath to the end of the connection string but it was unsuccessfully, I would just get this error:

The path to an Event Hub may be specified as part of the connection string or as a separate value, but not both. Please verify that your connection string does not have the EntityPath token if you are passing an explicit Event Hub name. (Parameter 'connectionString')'

Any idea of what I could be missing or doing wrong?


Solution

  • I think the problem here is not with the Function App code.

    Please check whether you have routed the data to built-in endpoint of the IoT Hub Consumer Group. This becomes necessary when you have multiple routes created on your IoT Hub.

    To create this route - Add another route on IoT Hub with Endpoint as events under Built in Endpoint

    enter image description here