gpt4 book ai didi

azure - 如何从另一个模块调用物联网边缘代理上的直接方法?

转载 作者:行者123 更新时间:2023-12-04 08:56:25 25 4
gpt4 key购买 nike

我正在尝试 1.0.10-rc2 的实验性功能。

edgeAgent UploadModuleLogs 上有一个直接的方法。

我可以从 Azure 门户调用该方法,并且工作正常。我正在尝试从同一设备上的模块调用该方法,如下所示:

static async Task Init()
{
...

await ioTHubModuleClient.SetMethodHandlerAsync("UploadModuleLogs", UploadModuleLogs, ioTHubModuleClient);
}

private static async Task<MethodResponse> UploadModuleLogs(MethodRequest methodRequest, object userContext)
{
ModuleClient ioTHubModuleClient = (ModuleClient)userContext;

// Upload logs
Console.WriteLine("Invoking method On edgeAgent");

var payload = @"{
""schemaVersion"": ""1.0"",
""sasUrl"": ""https://..."",
""items"": [
{
""id"": "".*"",
""filter"": {
""tail"": 100
}
}
],
""encoding"": ""none"",
""contentType"": ""text""
} ";

MethodRequest request = new MethodRequest("UploadModuleLogs", Encoding.UTF8.GetBytes(payload));

string myModuleId = Environment.GetEnvironmentVariable("IOTEDGE_MODULEID");
string myDeviceId = Environment.GetEnvironmentVariable("IOTEDGE_DEVICEID");

Console.WriteLine($"{myDeviceId} {myModuleId} - UploadModuleLogs method request at {DateTime.Now}");
//Console.WriteLine($"{request.DataAsJson}");

try
{
var response = await ioTHubModuleClient.InvokeMethodAsync(myDeviceId, "$edgeAgent", request).ConfigureAwait(false);
Console.WriteLine($"Received response with status: {response.Status} with message: {response.ResultAsJson}");

return response;
}
catch (Exception ex)
{
Console.WriteLine($"Error invoking method {ex}");
}

return null;

尝试运行此:

调用方法 Microsoft.Azure.Devices.Client.Exceptions.DeviceNotFoundException 时出错:设备 {"message":"Client myDeviceName/$edgeAgent not found"} 未注册在 Microsoft.Azure.Devices.Client.Transport.HttpClientHelper.ExecuteAsync(HttpMethod httpMethod, Uri requestUri, Func3modifyRequestMessageAsync, Func2 isSuccessful, Func3 processResponseMessageAsync, IDictionary2 errorMappingOverrides , CancellationToken 取消 token )在 Microsoft.Azure.Devices.Client.Transport.HttpClientHelper.PostAsync[T1,T2](Uri requestUri,T1 实体,IDictionary2 errorMappingOverrides,IDictionary2 customHeaders,CancellationToken CancellationToken)在 Microsoft.Azure.Devices.Client.ModuleClient.InvokeMethodAsync(Uri uri, MethodRequest methodRequest, CancellationToken CancellationToken)

最佳答案

这是预期的行为,其他模块无法调用边缘代理的直接方法。边缘代理在设计上并未连接到edgeHub,因为代理的直接方法具有特权并且需要服务信用才能访问。

关于azure - 如何从另一个模块调用物联网边缘代理上的直接方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63806134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com