【发布时间】:2019-07-29 21:19:17
【问题描述】:
我使用 IoT 中心触发器创建了一个 azure 函数。作为一个例子,我使用这个Azure Functions - how to set up IoTHubTrigger for my IoTHub messages?
函数1.cs
using IoTHubTrigger = Microsoft.Azure.WebJobs.ServiceBus.EventHubTriggerAttribute;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.ServiceBus.Messaging;
using System.Text;
using System.Net.Http;
namespace LogTheIoTHubMessage
{
public static class Function1
{
private static HttpClient client = new HttpClient();
[FunctionName("Function1")]
public static void Run([IoTHubTrigger("messages/events", Connection = "ConnectionString")]EventData message, TraceWriter log)
{
log.Info($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.GetBytes())}");
}
}
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"ConnectionString": "HostName=AAA.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=YYYYYY"
}
}
但是当我测试该功能时,它会启动但触发器不会触发。对于测试,我使用
C:\Program Files\mosquitto>mosquitto_pub -d -h AAA.azure-devices.net -i TestRaspberryPi -u "AAA.azure-devices.net/TestRaspberryPi" -P "SharedAccessSignature sr=YYY" -m "noch ein test" -t “设备/TestRaspberryPi/消息/事件/readpipe/”--cafile "c:\Projects\azureiot.pem" -p 8883 -V mqttv311
客户端 TestRaspberryPi 发送 CONNECT 客户端 TestRaspberryPi 接收 CONNACK (0) 客户端 TestRaspberryPi 发送 PUBLISH (d0, q0, r0, m1, 'devices/TestRaspberryPi/messages/events/readpipe/', ... (13 bytes)) 客户端 TestRaspberryPi 发送 DISCONNECT
【问题讨论】:
-
您能否指出有关您方法的官方文档?
标签: azure-functions azure-iot-hub