谷歌云数据流java API没有读取其他项目的pubsub主题

问题描述 投票:1回答:1

我只有一个在生产项目中创建的主题。我想在开发环境中运行我的数据流作业,这需要使用生产pubsub主题。当我在开发项目中提交我的数据流作业时,它不起作用,它总是显示在数据流UI中运行但不读取pubsub中的任何元素。如果我提交给生产项目它完美地运作。

为什么不读取来自不同项目主题的消息?我正在使用java-sdk 2.1并且运行器是“dataflowrunner”

PCollection<String> StreamData = p.apply("Read pubsub message",PubsubIO.readStrings().fromSubscription(options.getInputPubSub()));

使用mvn提交数据流作业

mvn compile exec:java -Dexec.mainClass=dataflow.streaming.SampleStream  -Dexec.args="—project=project-dev-1276 --stagingLocation=gs://project-dev/dataflow/staging --tempLocation=gs://project-dev/dataflow/bq_temp  --zone=europe-west1-c  --bigQueryDataset=stream_events --bigQueryTable=events_sample --inputPubSub=projects/project-prod/subscriptions/stream-events --streaming=true --runner=dataflowRunner"

注意:如果我使用directrunner,它将工作并使用来自不同项目pubsub主题的消息。 enter image description here

队列中没有添加任何元素,也没有估计的大小。

google-cloud-dataflow google-api-java-client google-cloud-pubsub dataflow apache-beam-io
1个回答
0
投票

您需要在生产项目中为您的作业将使用的用户(服务帐户)添加Pub/Sub Subscriber权限。默认情况下,工作人员使用项目的Compute Engine服务帐户作为控制器服务帐户。该服务帐户(<project-number>[email protected])应获得Pub/Sub Subscriber许可。

在这里阅读更多https://cloud.google.com/dataflow/docs/concepts/security-and-permissionshttps://cloud.google.com/pubsub/docs/access-control

© www.soinside.com 2019 - 2024. All rights reserved.