发生错误发送事件:Azure函数输出适配器未能将事件写入Azure函数作为Stream Analytics作业输出 [英] An error occurred Send Events: Azure Function Output Adapter failed to write events Azure Function as Stream Analytics Job Output

查看:121
本文介绍了发生错误发送事件:Azure函数输出适配器未能将事件写入Azure函数作为Stream Analytics作业输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure IoT开发套件MXChip,并且正在将传感器数据发送到IoT中心.我还设置了流分析作业,将输入作为IoT中心,将输出作为SQL Server和Azure函数.输出将被写入SQL数据库,因此,我确认查询是正确的.

I have an Azure IoT Dev Kit MXChip and I am sending the sensor data to the IoT Hub. I have also set up the Stream Analytics Job with Input as IoT Hub and Output as SQL Server and Azure Function. The output is getting written to the SQL Database, so I am confirming that the Query is correct.

当我检查流分析作业日志时,看到如下错误.

When I check my stream analytics job log, I am seeing some error as below.

{
    "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功能代码.

Below is my Azure Function code.

[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函数代码.

I think I figured it out, I changed my Azure Function code as follows.

[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函数时,我会看到错误消息,因为没有MediaTypeFormatter可从媒体类型为'application/octet-stream'的内容中读取类型为'Object'的对象."我以字符串形式获取数据并反序列化相同.

When I monitor my Azure function, I could see that I was getting an error as "No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'application/octet-stream'.", so I get the data as string and deserialized the same.

除此之外,我还将函数的 TLS版本设置为1.0,这非常重要,Microsoft发出更改警告,但没有错误.

Apart from that, I also set the TLS version of my function to 1.0, this is very important, Microsoft is giving the warning to change but not an error.

现在,通过Monitor选项,该功能可以正常工作,没有任何错误.您还可以查看文档这里.

Now the function is working fine without any errors, from the monitor option. You can also see the documentation here.

这篇关于发生错误发送事件:Azure函数输出适配器未能将事件写入Azure函数作为Stream Analytics作业输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆