0
votes

I am trying to send the data to IoT Hub which sends the data to the stream analytics and then to Event Hub. Azure function gets triggered as soon as the message is entered into the event hub. The problem I am facing is that when I send 10 messages from the VS Code(send D2C message to IoT Hub) option. The function throws this error:

Binding parameters to complex objects (such as 'Object') uses Json.NET serialization. 1. Bind the parameter type as 'string' instead of 'Object' to get the raw values and avoid JSON deserialization, or 2. Change the queue payload to be valid json. The JSON parser failed: Unexpected character encountered while parsing value: Path '', line 0, position 0.

As per my investigation, this message points to the invalid json, however this is not the case. My json is correct and valid because my function parses it correctly. This problem occurs when I start scaling upwards(send more messages in less intervals) to the IoT Hub. I am not sure what is causing it. If the message is not correct then the function should throw the error for every message rather than randomly throwing the error. In addition, this exception is not caught because this happens at the azure side not within my function code. My function.json is as follows:

{
  "scriptFile": "main.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "event",
      "direction": "in",
      "eventHubName": "myhubName",
      "connection": "myConnectionString",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}

I am not sure what I am missing in this file? I do not want to scale down my cardinality(one) option since the current option is the recommended one. similar issue can be seen here. In this case they might not have a valid json but a string. Although in my case its always json so I cannot use dataType: string property.

main.py

import logging
import sys
from sys import path
import os
import traceback
import azure.functions as func
from azure.storage.blob import BlockBlobService
import json

def main(event: func.EventHubEvent):
  try:
    # prints the message
    print("*******************************************")
    print(event.iothub_metadata)
    print(event.get_body())

  except:
        # Logs the stack trace to the root level when errors occurs
    logging.error("Unexpected Error: " + traceback.format_exc())
    pass
1
Does the 10 messages exceeds 1M?Ivan Yang
No, for 10 messages it would be around 80 KB Maximum.Hassan Abbas

1 Answers

0
votes

As mentioned here, you need to create DefaultType for the EventHubs trigger attribute and making sure that it is registered in the metadata provider

example code here.