Hi @Nayangiri Goswami Greetings! Thank you for posting this question here.
I could reproduce the same issue you are facing with Python application when trying to process a message triggered from Device Connection Status event generated from IoT Hub through event routing.
I notice that the message body for the message generated through this event consists only a sequenceNumber
property in the above-mentioned Base 10 format. The function app is trying to format this sequnceNumber
property to an int even before entering the code which is leading to the above error.
Instead of going with routing in IoT Hub, use Events
under IoT Hub and create an Event subscription to filter Device Connected
and Device Disconnected
event types. Choose the end point as Service Bus Queue and point to your queue to send the events. Please find the below image for reference
Once you have this configured, disable any routes you may have under the IoT Hub that sends Device Connection status to the Service Bus Queue end point.
The message delivered to the queue using the event subscription have a different template. Please find the below message body for reference
You can then use the below Function app code to process the message body and extract the sequence number
@app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="lsayanaiot",
connection="lsayanaservicebus_SERVICEBUS")
def lsayana_servicebus_queue_trigger(azservicebus: func.ServiceBusMessage):
message_body = json.loads(azservicebus.get_body().decode('utf-8'))
logging.info('Message body is %s', message_body)
sequence_number = message_body['data']['deviceConnectionStateEventInfo']['sequenceNumber']
logging.info('Python ServiceBus Queue trigger processed a message: %s',
sequence_number)
Hope this helps! Please let us know if you have any additional questions or need further assistance.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.