尝试将具有存储在 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()
Run Code Online (Sandbox Code Playgroud)
预计能够列出属性数据:
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",
Run Code Online (Sandbox Code Playgroud)
,但我似乎只能访问存储在数据字段中的信息 - 而不是属性。