0

I have created a eventhub trigger azure func in python, I am unable to read the event message by using the below code,

import logging
import azure.functions as func

def main(event: func.EventHubEvent):
    logging.info('Event Hubs trigger function processed message: ', event.get_body())
    logging.info('  EnqueuedTimeUtc =', event.enqueued_time)
    logging.info('  SequenceNumber =', event.sequence_number)
    logging.info('  Offset =', event.offset)

how to call the main function which is having the param? Kindly help on this!!

I also tried to create object, but since its a abstract class module, i am getting error,

def main(event):

print(event)

e = event()

print('Event Hubs trigger function processed message: ', e.get_body())

And the error is:

main(func.EventHubEvent)
Microsoft.Azure.WebJobs.Script: Traceback (most recent call last): File 
"D:\home\site\wwwroot\CDPConversion\run.py",
line 92, in <module> main(func.EventHubEvent) File 
"D:\home\site\wwwroot\CDPConversion\run.py", line 85, in main e = 
event() TypeError: Can't instantiate abstract class EventHubEvent with 
abstract methods enqueued_time, get_body, offset, partition_key, sequence_number 

Kindly provide a solution to read the message/events from eventhub.

Mark
  • 5,994
  • 5
  • 42
  • 55
Jay
  • 43
  • 1
  • 6

1 Answers1

0

Jay,

Your class needs to define an implementation of get_body and others'; it's an abstract method and concrete subclasses must implement it.

Check this thread for further explanation:

“Can't instantiate abstract class … with abstract methods” on class that shouldn't have any abstract method

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27