如何在数据流管道中读取PubSub子目录

2024-10-01 17:31:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在通过MQTT向谷歌物联网核心发送消息。
我的物联网注册表关联到3个子主题,每个主题有几个子目录

我的消息被转发到PubSub,然后由数据流管道处理。
在我的管道中,我阅读了Pub/Sub的以下内容:

    common = (
        pipeline
        | 'Get common on pub/sub' >> beam.io.ReadFromPubSub(
        topic='projects/project-id/topics/topics-id',
    with_attributes=True)
)

但是我想能够从我的pubsub主题子目录中阅读,可以吗?
我已经尝试过这样添加它:

topic='projects/project-id/topics/topics-id/sub-directory'

不成功


Tags: projectid消息核心主题topic管道注册表
1条回答
网友
1楼 · 发布于 2024-10-01 17:31:36

您可以发布到其他子目录主题,并对这些主题进行单独订阅。从documentation on publishing telemetry events to additional Cloud Pub/Sub topics开始:

Devices can publish data to additional Cloud Pub/Sub topics. By default, MQTT messages published to /devices/DEVICE_ID/events are forwarded to the corresponding registry's default telemetry topic. You can specify a subfolder in the MQTT topic to forward data to additional Cloud Pub/Sub topics. The subfolder is the subtopic after /devices/DEVICE_ID/events.

上面链接的文档提供了有关如何设置的更多详细信息,以及消息将和不会发布到子目录主题的情况

相关问题 更多 >

    热门问题