Reputation: 2666
I'm following this example to process messages received from Event Hub:
https://github.com/Azure/azure-event-hubs-python/blob/master/examples/eph.py
But, the code does show any code on how to retrieve each message and get to the Json payload?
I have tried the following code (using the Python SDK for Event Hub):
async def process_events_async(self, context, messages):
"""
Called by the processor host when a batch of events has arrived.
This is where the real work of the event processor is done.
:param context: Information about the partition
:type context: ~azure.eventprocessorhost.PartitionContext
:param messages: The events to be processed.
:type messages: list[~azure.eventhub.common.EventData]
"""
for message in messages:
message_content = json.loads(message.body)
logger.info("Events processed {}".format(context.sequence_number))
await context.checkpoint_async()
But, I get the following error message on the statement conaining json.loads:
"2018-09-20 23:13:12,484 azure ERROR Event Processor Error TypeError("the JSON object must be str, bytes or bytearray, not 'generator'",)"
Can you help me with the code to get to the Json payload of the message?
Upvotes: 0
Views: 1350
Reputation: 2666
This is working code to get to the JSON payload of the Event Hub messages:
for message in messages:
message_body = list(message.body)
message_content = json.loads(message_body[0])
Upvotes: 1