Apache Beam:无法从 GCP PubSub 读取消息错误是 AttributeError: 'SubscriberGrpcTransport' object has no attribute 'channel'

问题描述

我正在开发方法评估所需的 POC。我的 Mac 上安装了 python、venv、apache beam 和 gcloud。而且,我已经登录了 gcloud pupsub。

以下代码,创建订阅我的 Pubsub 主题并读取来自 PubSub 的消息。

步骤:

  1. 执行代码
  2. 转到 gcloud poubsub 主题并发布一条简单消息
  3. 代码读取消息并创建输出文件

但没有运气,我收到以下错误:AttributeError: 'SubscriberGrpcTransport' object has no attribute 'channel'

代码:

def run(argv=None): 
parser = argparse.ArgumentParser() 
parser.add_argument( 
   '--topic',type=str,help='Pub/sub topic to read from') 
parser.add_argument( 
   '--output',help=('Output local filename')) 
args,pipeline_args = parser.parse_known_args(argv) 
options = PipelineOptions(pipeline_args) 
options.view_as(SetupOptions).save_main_session = True 
options.view_as(StandardOptions).streaming = True 

p = beam.Pipeline(options=options) 
(p | 'Read from PubSub' >> beam.io.ReadStringsFromPubSub(topic=args.topic) 
   | 'Write to file' >> beam.io.WriteToText(args.output) 
) 
result = p.run() 
result.wait_until_finish() 

if __name__ == '__main__': 
run() 

并参考视频: https://www.youtube.com/watch?v=I1JUtoDHFcg 9:13 分钟。

请通过您的专家帮助来解决问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)