Azure功能 - 物联网中心 - Python [英] Azure Functions - IoT Hub - Python

查看:68
本文介绍了Azure功能 - 物联网中心 - Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在寻找一些关于是否可以使用以Python编写的IoT Hub触发Azure功能的答案?我已经看到可以做事件集线器触发器但是想知道是否可以为物联网中心做这件事。我通过Azure门户很容易地在
C#中配置了这个,但由于Python实现仍在预览中,我只是想在我投入大量时间之前检查功能是否存在。如果有,有没有资源可以帮助生成
IoT Hub Python函数?

I'm looking for some answers on whether using an IoT Hub triggered Azure Function written in Python is currently possible? I've seen it's possible to do event hub triggers but was wondering whether this can be done for the IoT Hub. I've configured this in C# through the Azure portal quite easily, but since the Python implementation is still in Preview, I just wanted to check that the functionality is there before I invest a significant amount of time in this. If so, are there any resources to assist in producing IoT Hub Python functions?

谢谢,

Sam 

Sam 

推荐答案

IoT Hub支持基于Azure事件中心绑定。你有没有经历过这个  documentation
Python中的IoT Hub触发器Azure函数示例

以下示例显示了一个事件中心触发器绑定function.json文件和使用绑定的Python函数。该函数读取

事件元数据
并记录消息。

The following example shows an event hub trigger binding in a function.json file and a Python function that uses the binding. The function reads event metadata and logs the message.

{
  "type": "eventHubTrigger",
  "name": "event",
  "direction": "in",
  "eventHubName": "MyEventHub",
  "connection": "myEventHubReadConnectionAppSetting"
}

这是Python代码:

Here's the Python code:

import logging
import azure.functions as func

def main(event: func.EventHubEvent):
    logging.info('Function triggered to process a message: ', event.get_body())
    logging.info('  EnqueuedTimeUtc =', event.enqueued_time)
    logging.info('  SequenceNumber =', event.sequence_number)
    logging.info('  Offset =', event.offset)


这篇关于Azure功能 - 物联网中心 - Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆