Share via

Why Azure Function doesn't work properly when it was defined as an Output from a Stream Analytics job?

Jeff Liu 91 Reputation points
2022-04-01T09:44:06.11+00:00

Hi MS Support,

Just a quick question. The Azure function to trigger an external HTTP api is running fine itself. But, when I config it as an Output of a Stream Analytics query, it doesn't seem to work fine.

(It seems that it keeps being triggered non-stop and not really being triggered when the rules in the Stream Analytics Query were matched.) And, after a while, a Runtime error occurs from the Stream Analytics dashboard. Please assist me with this.

I also have another question. How to carry forward data from Stream Analytics Query into Azure Function? For example, the Query will send a data record to Output when the temperature is 31 degrees, which is greater than the 30 degrees being defined in the Query. Then, how to carry forward this "temperature is 31 degrees" into the Azure Function? Thanks a lot.!

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


Answer accepted by question author

MayankBargali-MSFT 71,016 Reputation points Moderator
2022-04-04T14:10:43.967+00:00

@Jeff Liu Thanks for your offline discussion. We have reviewed the configuration and found that the Stream Analytics job was configured correctly with the azure function.
Stream analytics job was able to trigger the function app correctly but due to function app code in a few of the scenarios, it was resulting in 500 internal errors.

We have reviewed the application insights logs to get more details on the exact error and fixed the function code.

Leveraged below code snippet to get the data in function app which was passed from Stream Analytics job and configure the output correctly at stream analytics end.

 try:  
        req_body = req.get_json()  
        logging.info(req_body)  
        for body in req_body:  
            logging.info(body.get('yourjsonproperty'))  
    except ValueError:  
        logging.info("No parameter found in request body")  
        return func.HttpResponse("No alert parameter found in request body",status_code=400)  
  
    return func.HttpResponse(  
        "HTTP triggered function executed successfully.",  
        status_code=200  
    )  

We have fixed the telegram API call with the out from stream analytics services and you confirmed that the message was successfully received at the telegram end.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.