简体   繁体   中英

Azure IotHubTrigger function gets never triggered in the cloud

I tried to create a Azure IotHubTrigger function (C#) that gets triggered when a new message arrives in the IotHub. My problem is that the function works locally to receive messages but when it is deployed the function gets never triggered. The app settings are also set in the Portal. Is it possible that I am missing some configuration to make it work in the cloud? I also tried to delete the function and recreate it and to use typescript instead of C# but nothing worked.

Below is the code of the function:

    [FunctionName("IoTHubTest")]
    public void Run([IoTHubTrigger("IotHubName", Connection = "IotHubConnectionString")]EventData message, ILogger log)
    {
        log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");
    }

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=... ",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "IotHubConnectionString": "Endpoint=sb:...",
    "IotHubName": "iothub-..."
  }
}

As per your information there is something which is missing during the deployment from local. Because it is working from local and also working when it is created from portal.

Follow the below steps to check the issue.

  1. Check how the function is getting triggered.
  2. Enable Application Insights for function.
  3. Check for the logs in Application Insights when the function gets triggered.

With this we can find the root cause.

Also along with this, there are two reason for the function app not triggering after deployment.

  1. Add the application settings under configuration in function app.
  2. If there are any connections made to storage, you need to add CORS. Try these steps and check if it is working or not. Also do share the error message if it is not resolved by you.

Apart from all these troubleshooting steps you share the information to Azure community. Check this GIT Azure function QnA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM