尝试将具有存储在 PubSub 中的属性的消息拉取到 Beam 管道中。我想知道是否添加了对 Python 的支持,这就是我无法阅读它们的原因。我看到它存在于Java中。
pipeline_options = PipelineOptions()
pipeline_options.view_as(StandardOptions).streaming = True
pipeline = beam.Pipeline(options=pipeline_options)
messages = (pipeline | beam.io.ReadFromPubSub(subscription=subscription_name).with_output_types(bytes))
def printattr(element):
print(element.attributes)
lines = messages | 'printattr' >> beam.Map(printattr)
result = pipeline.run()
result.wait_until_finish()
期望能够列出属性-数据:
b'Message number 1109'
- attributes: {
- "_comments": "nan",
- "_direction": "SE",
- "_fromst": "Harlem",
- "_last_updt": "2019-03-20 21:11:02.0",
- "_length": "0.56",
- "_lif_lat": "41.9809967484",
- "_lit_lat": "41.9787314076",
- "_lit_lon": "-87.7964600566",
- "_strheading": "W",
- "_tost": "Oak Park",
,但我似乎只能访问存储在数据字段中的信息,而不能访问属性。
查看文档后:https://beam.apache.org/releases/pydoc/2.11.0/apache_beam.io.gcp.pubsub.html https://beam.apache.org/releases/pydoc/2.11.0/apache_beam.io.gcp.pubsub.html,我能够看到传递给 ReadFromPubSub 的附加参数。
需要设置“with_attributes=True”,否则,您只能获取数据字段。
希望这可以帮助其他可能陷入困境或只是感到疲倦的人:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)