Stream Analytics Egress to Azure Functions

孤街浪徒 提交于 2019-12-13 17:33:46

问题


Microsoft announced support for sending data from Azure Stream Analytics to Azure Functions few days back:

https://azure.microsoft.com/en-us/blog/new-in-stream-analytics-output-to-azure-functions-built-in-anomaly-detection-etc/

I tried this but couldn't send data to Azure Functions. Is there any guide how to send data packet from IoT-hub -> Azure Stream Analytics -> Azure Functions?

The output is fine to other sources. This is the query I have:

WITH rpidata AS
(
SELECT 
*, 
DATEADD(Hour, 3, timecreated) AS FITimezone
FROM [rpi]
)
SELECT *
INTO [PowerBI]
FROM rpidata
SELECT *
INTO [storageout]
FROM rpidata
SELECT *
INTO [fnout]
FROM rpidata

The error message I get is:

Could not successfully send an empty batch to the Azure Function. Please make sure your function app name, function name, and API key are correct and that your Azure Function compiles. If all of those parameters are correct, Azure Function may be temporarily available at this time. Please try again later. Azure function returned with response code of 500: InternalServerError. It should respond with a 200, 202, or 204.

However the function is there, is running and is found automatically when I try to create the connection.

What kind of Function input I should use to receive the data? I n the example I linked function name is httptriggercsharp... Does streamjob send the data as json?


回答1:


Not sure if you still need this, but for future reference: The ASA job will output the data in a JSON array to your Azure function. An example ASA query like this

SELECT
   w.col1 as key1,
   w.col2 as key2,
   System.Timestamp as time
INTO
   azfunction
FROM
   [input] w;

will arrive in your Function like this

[
         {
             "key1":"value1",
             "key2":"value2",
             "time":"2017-09-04T17:51:02.7986986Z"
         },
         {
             "key1":"value3",
             "key2":"value4",
             "time":"2017-09-04T17:51:02.7986986Z"
         }
]

How many elements the JSON array will contain, depends on how you set up the Az Function output in ASA as well as on how fast events arrive in ASA. The array might only have one element or 100 depending on your scenario.




回答2:


According to your description and error message, I guess there are something wrong with your azure functions codes(It returns a 500 error).

I suggest you could firstly check the azure function logs to find the details error message and change your codes.

Details you could refer to below images:

Open the azure function app and find monitor

I also create a test stream analysis to azure function. I found the stream analysis will send json to azure function.

I suggest you could also use this codes(Http trigger) to test your could get the result:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");
     var content = req.Content;
    string jsonContent = await content.ReadAsStringAsync();

    log.Info(jsonContent);

    return   req.CreateResponse(HttpStatusCode.OK, jsonContent);
}

Result:




回答3:


Just to complement this answer , You can use mock data from mockaroo.

https://mockaroo.com/

To test the code mentioned above:

{
    "DeviceID": 8,
    "Temperature": 28,
    "Unit": 40,
    "TimeStamp": "2018-03-23T17:43:18.0000000Z",
    "EventProcessedUtcTime": "2018-03-23T17:44:36.5010819Z",
    "PartitionId": 0,
    "EventEnqueuedUtcTime": "2018-03-23T17:43:18.5700000Z"
},

{
    "DeviceID": 8,
    "Temperature": 66,
    "Unit": 27,
    "TimeStamp": "2018-03-23T17:43:20.0000000Z",
    "EventProcessedUtcTime": "2018-03-23T17:44:36.8143642Z",
    "PartitionId": 1,
    "EventEnqueuedUtcTime": "2018-03-23T17:43:21.0090000Z"
}


来源:https://stackoverflow.com/questions/46514057/stream-analytics-egress-to-azure-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!