天蓝色函数-eventhub触发py函数

时间:2019-02-18 10:08:44

标签: python azure-functions azure-eventhub

我已经在python中创建了一个eventhub触发器azure func,我无法通过使用以下代码来读取事件消息,

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)

如何调用具有参数的主函数?请对此提供帮助!

我也尝试创建对象,但是由于它是一个抽象类模块,因此出现错误,

def main(event):

print(event)

e = event()

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

错误是:

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 

请提供一种从eventhub读取消息/事件的解决方案。

1 个答案:

答案 0 :(得分:0)

周杰伦

您的课程需要定义get_body和其他用户的实现;这是一种抽象方法,必须由具体的子类实现。

检查该线程以获取进一步的解释:

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

希望有帮助。