发送事件时发生错误:Azure 函数输出适配器无法将事件 Azure 函数写入流分析作业输出
An error occurred Send Events: Azure Function Output Adapter failed to write events Azure Function as Stream Analytics Job Output
我有一个 Azure IoT 开发工具包 MXChip,我正在将传感器数据发送到 IoT 中心。我还设置了流分析作业,输入为 IoT 中心,输出为 SQL 服务器和 Azure 函数。输出被写入 SQL 数据库,所以我确认查询是正确的。
当我检查我的流分析作业日志时,我看到如下错误。
{
"channels": "Operation",
"correlationId": "4a9c9b61-631a-4f4f-a403-c2869b2af66c",
"description": "",
"eventDataId": "97250faf-fa47-4e78-9981-8429f293bab9",
"eventName": {
"value": "streamingNode0",
"localizedValue": "streamingNode0"
},
"category": {
"value": "Administrative",
"localizedValue": "Administrative"
},
"eventTimestamp": "2018-12-18T15:54:22.9777487Z",
"id": "",
"level": "Error",
"operationId": "a613bc6a-5f61-4064-bea5-83c3af232e68",
"operationName": {
"value": "Send Events: Azure Function Output Adapter failed to write events",
"localizedValue": "Send Events: Azure Function Output Adapter failed to write events"
},
"resourceGroupName": "mlIoTPlatformDev",
"resourceProviderName": {
"value": "Microsoft.StreamAnalytics",
"localizedValue": "Microsoft.StreamAnalytics"
},
"resourceType": {
"value": "Microsoft.StreamAnalytics/streamingjobs",
"localizedValue": "Microsoft.StreamAnalytics/streamingjobs"
},
"resourceId": "",
"status": {
"value": "Failed",
"localizedValue": "Failed"
},
"subStatus": {
"value": "",
"localizedValue": ""
},
"submissionTimestamp": "2018-12-18T15:55:04.0799116Z",
"subscriptionId": "",
"properties": {
"Message Time": "2018-12-18 15:54:22Z",
"Error": "- An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n",
"Message": "Failed to write events. Error encountered after writing [0] batches., - An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n, : OutputSourceAlias:AzureFunctionOutput;AdapterType:AzureFunction;ShardId:0;",
"Type": "AzureFunctionOutputAdapterFailure",
"Correlation ID": "4a9c9b61-631a-4f4f-a403-c2869b2af66c"
},
"relatedEvents": []
}
下面是我的 Azure 函数代码。
[FunctionName("GetData")]
public static async Task < HttpResponseMessage > Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
// [SignalR(HubName = "ml-iot-platform")] IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log) {
log.LogInformation($ "GetData function triggered with Uri {req.RequestUri}");
dynamic data = await req.Content.ReadAsAsync < object > ();
log.LogInformation($ "Data count is {data.Count}");
if (data.ToString().Length > 262144) {
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
}
//await signalRMessages.AddAsync(new SignalRMessage()
//{
// Target = "checkData",
// Arguments = new object[] { data }
//});
return req.CreateResponse(HttpStatusCode.OK, "Success");
}
你遇到过这个问题吗?
我想我明白了,我按如下方式更改了我的 Azure 函数代码。
[FunctionName("GetData")]
public static async Task < HttpResponseMessage > Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req,
ILogger log) {
log.LogInformation($ "GetData function triggered with Uri {req.RequestUri}");
string content = await req.Content.ReadAsStringAsync();
log.LogInformation($ "String content is {content}");
dynamic data = JsonConvert.DeserializeObject(content);
log.LogInformation($ "Data count is {data?.Count}");
if (data ? .ToString() ? .Length > 262144) {
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
}
return req.CreateResponse(HttpStatusCode.OK, "Success");
}
当我监控我的 Azure 函数时,我可以看到我收到一个错误 "No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'application/octet-stream'.",所以我将数据作为字符串获取并对其进行反序列化。
除此之外,我还将函数的 TLS version 设置为 1.0,这很重要,Microsoft 只是警告更改但不是错误。
现在该功能可以正常工作,没有任何错误,来自监控选项。您还可以查看文档 here。
我有一个 Azure IoT 开发工具包 MXChip,我正在将传感器数据发送到 IoT 中心。我还设置了流分析作业,输入为 IoT 中心,输出为 SQL 服务器和 Azure 函数。输出被写入 SQL 数据库,所以我确认查询是正确的。
当我检查我的流分析作业日志时,我看到如下错误。
{
"channels": "Operation",
"correlationId": "4a9c9b61-631a-4f4f-a403-c2869b2af66c",
"description": "",
"eventDataId": "97250faf-fa47-4e78-9981-8429f293bab9",
"eventName": {
"value": "streamingNode0",
"localizedValue": "streamingNode0"
},
"category": {
"value": "Administrative",
"localizedValue": "Administrative"
},
"eventTimestamp": "2018-12-18T15:54:22.9777487Z",
"id": "",
"level": "Error",
"operationId": "a613bc6a-5f61-4064-bea5-83c3af232e68",
"operationName": {
"value": "Send Events: Azure Function Output Adapter failed to write events",
"localizedValue": "Send Events: Azure Function Output Adapter failed to write events"
},
"resourceGroupName": "mlIoTPlatformDev",
"resourceProviderName": {
"value": "Microsoft.StreamAnalytics",
"localizedValue": "Microsoft.StreamAnalytics"
},
"resourceType": {
"value": "Microsoft.StreamAnalytics/streamingjobs",
"localizedValue": "Microsoft.StreamAnalytics/streamingjobs"
},
"resourceId": "",
"status": {
"value": "Failed",
"localizedValue": "Failed"
},
"subStatus": {
"value": "",
"localizedValue": ""
},
"submissionTimestamp": "2018-12-18T15:55:04.0799116Z",
"subscriptionId": "",
"properties": {
"Message Time": "2018-12-18 15:54:22Z",
"Error": "- An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n",
"Message": "Failed to write events. Error encountered after writing [0] batches., - An error occurred while sending the request.\r\n- The underlying connection was closed: An unexpected error occurred on a send.\r\n- Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.\r\n- An existing connection was forcibly closed by the remote host\r\n, : OutputSourceAlias:AzureFunctionOutput;AdapterType:AzureFunction;ShardId:0;",
"Type": "AzureFunctionOutputAdapterFailure",
"Correlation ID": "4a9c9b61-631a-4f4f-a403-c2869b2af66c"
},
"relatedEvents": []
}
下面是我的 Azure 函数代码。
[FunctionName("GetData")]
public static async Task < HttpResponseMessage > Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
// [SignalR(HubName = "ml-iot-platform")] IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log) {
log.LogInformation($ "GetData function triggered with Uri {req.RequestUri}");
dynamic data = await req.Content.ReadAsAsync < object > ();
log.LogInformation($ "Data count is {data.Count}");
if (data.ToString().Length > 262144) {
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
}
//await signalRMessages.AddAsync(new SignalRMessage()
//{
// Target = "checkData",
// Arguments = new object[] { data }
//});
return req.CreateResponse(HttpStatusCode.OK, "Success");
}
你遇到过这个问题吗?
我想我明白了,我按如下方式更改了我的 Azure 函数代码。
[FunctionName("GetData")]
public static async Task < HttpResponseMessage > Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req,
ILogger log) {
log.LogInformation($ "GetData function triggered with Uri {req.RequestUri}");
string content = await req.Content.ReadAsStringAsync();
log.LogInformation($ "String content is {content}");
dynamic data = JsonConvert.DeserializeObject(content);
log.LogInformation($ "Data count is {data?.Count}");
if (data ? .ToString() ? .Length > 262144) {
return new HttpResponseMessage(HttpStatusCode.RequestEntityTooLarge);
}
return req.CreateResponse(HttpStatusCode.OK, "Success");
}
当我监控我的 Azure 函数时,我可以看到我收到一个错误 "No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'application/octet-stream'.",所以我将数据作为字符串获取并对其进行反序列化。
除此之外,我还将函数的 TLS version 设置为 1.0,这很重要,Microsoft 只是警告更改但不是错误。
现在该功能可以正常工作,没有任何错误,来自监控选项。您还可以查看文档 here。