0

I have created a function with an Event Hub Trigger. It has been working as expected until today.

import logging
import datetime
import json
import azure.functions as func


def main(event: func.EventHubEvent, msg: func.Out[func.QueueMessage]):
    try:
        # take the number from the event
        number = json.loads(event.get_body().decode('utf-8'))[0]["number"]

        # send number to queue
        msg.set(number)

        logging.info('Receive function processed ' + number + '.')

    except Exception as err:
        logging.error('Event hub message did not contain number. Error: ' + str(err))

The function is raising an error

Event hub message did not contain number. Error: 'list' object has no attribute 'get_body'

and I can see traces in the logs in Application Insights that contain the message:

An Event Hub exception of type 'ReceiverDisconnectedException' was thrown from Partition Id: '0'. This exception type is typically a result of Event Hub processor rebalancing and can be safely ignored

When I run the function locally with VS code, it is able to read the messages from event hubs.

Any idea why it's stopped working?

1 Answers1

0

I fixed it by changing this line of code, which still works when run locally with VS code

json.loads(event.get_body().decode('utf-8'))[0]["number"]

to this

json.loads(event[0].get_body().decode('utf-8'))["number"]

This now works when I run the function in Azure. Not sure why the formatting has changed.

I've specified the versions of modules in the requirements.txt file.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Ended up changing my function using this article, a lot more helpful than the microsoft doc https://medium.com/analytics-vidhya/azure-functions-event-hub-2603e8804f73 – Midnight Frost Jun 12 '20 at 08:50