C#中的IoT Edge模块可以输入多少条消息?所有示例均显示“ input1”,但除此之外没有其他内容。文档没有提及“ input1”以外的任何内容。
我正在尝试在单个IoT Edge C#模块中使用多个输入,但不确定如何执行此操作。该示例程序设置了连接到称为PipeMessage的输入消息处理程序的“ input1”。当将该模块与默认路由一起使用时,所有功能都可以正常工作。尝试添加第二个输入消息处理程序并调用输入“ input2”并添加一些路由时,没有任何反应。我们该如何在C#IoT Edge模块中设置多个输入?
program.cs Task Init()使用称为PipeMessage的回调方法设置输入消息处理程序。我复制了此代码,并更改了第二个输入的名称,但没有进行。
static async Task Init()
{
AmqpTransportSettings amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);
ITransportSettings[] settings = { amqpSetting };
// Open a first connection to the Edge runtime
ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
// Register callback to be called when a message is received by the module on input1
await ioTHubModuleClient.SetInputMessageHandlerAsync("input1", PipeMessage, ioTHubModuleClient);
// Open a second connection to the Edge runtime
ModuleClient ioTHubModuleClient2 = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient2.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
// Register callback to be called when a message is received by the module on input2
await ioTHubModuleClient2.SetInputMessageHandlerAsync("input2", PipeMessage2, ioTHubModuleClient);
}
`
和路线如下:
"routes": {
"CSharpFilter2ToIoTHub": "FROM /messages/modules/CSharpFilter2/outputs/* INTO $upstream",
"sensor1ToCSharpFilter2": "FROM /messages/modules/tempSensor1/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/CSharpFilter2/inputs/input1\")",
"sensor2ToCSharpFilter2": "FROM /messages/modules/tempSensor2/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/CSharpFilter2/inputs/input2\")"
},
我在做什么错了?
更具体地说,我们应该如何处理IoT Edge模块中的多个输入?
答案 0 :(得分:0)
您不需要(或应该)创建第二个ModuleClient。相反,只需多次调用SetInputMessageHandlerAsync():
ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient.OpenAsync();
await ioTHubModuleClient.SetInputMessageHandlerAsync("input1", PipeMessage1, ioTHubModuleClient);
await ioTHubModuleClient.SetInputMessageHandlerAsync("input2", PipeMessage2, ioTHubModuleClient);