Google cloud dataflow 使用来自google数据流的现有发布订阅

Google cloud dataflow 使用来自google数据流的现有发布订阅,google-cloud-dataflow,google-cloud-pubsub,Google Cloud Dataflow,Google Cloud Pubsub,我使用谷歌数据流,在其中一个步骤中,我使用已经创建的订阅订阅pub sub中的主题。 下面是代码片段 CustomPipelineOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(customPipelineOptions.class); Pipeline p = Pipeline.create(options); PCollection<Tabl

我使用谷歌数据流,在其中一个步骤中,我使用已经创建的订阅订阅pub sub中的主题。 下面是代码片段

CustomPipelineOptions options =
            PipelineOptionsFactory.fromArgs(args).withValidation().as(customPipelineOptions.class);
    Pipeline p = Pipeline.create(options);

    PCollection<TableRow> datastream = p.apply(PubsubIO.Read.named("Read device  data from PubSub")                 .subscription("projects/<projectID>/subscriptions/<subscriptionname>)
            .topic(String.format("projects/%s/topics/%s", options.getSourceProject(), options.getSourceTopic()))
            .timestampLabel("ts")
            .withCoder(TableRowJsonCoder.of()));
CustomPipelineOptions选项=
PipelineOptions工厂.fromArgs(args).withValidation().as(customPipelineOptions.class);
Pipeline p=Pipeline.create(选项);
PCollection datastream=p.apply(PubsubIO.Read.named(“从PubSub读取设备数据”).subscription(“项目//订阅”)
.topic(String.format(“projects/%s/topics/%s”、options.getSourceProject()、options.getSourceTopic()))
.时间标签(“ts”)
.withCoder(TableRowJsonCoder.of());
执行上述代码时会导致以下错误: 处理管道时出错。原因:(b5e276ef8c76419f):步骤s1的输入订阅无法识别

我正在传递正确的订阅名称和项目ID。 不知道为什么我仍然得到上述错误


请提供帮助。

指定两个来源之一就足够了:主题或订阅

我建议你试试:

PCollection<TableRow> datastream = p
        .apply(PubsubIO.Read.named("Read device data from PubSub")
        .topic(String.format("projects/%s/topics/%s", options.getSourceProject(), options.getSourceTopic()))
        .timestampLabel("ts")
        .withCoder(TableRowJsonCoder.of()));
PCollection datastream=p
.apply(PubsubIO.Read.named(“从PubSub读取设备数据”)
.topic(String.format(“projects/%s/topics/%s”、options.getSourceProject()、options.getSourceTopic()))
.时间标签(“ts”)
.withCoder(TableRowJsonCoder.of());

另外:我假设您正在使用Dataflow 1.9 SDK?您可能需要考虑移动到。您可以在该SDK中找到PubSub的参考。

指定两个源中的一个就足够了:主题或订阅

我建议你试试:

PCollection<TableRow> datastream = p
        .apply(PubsubIO.Read.named("Read device data from PubSub")
        .topic(String.format("projects/%s/topics/%s", options.getSourceProject(), options.getSourceTopic()))
        .timestampLabel("ts")
        .withCoder(TableRowJsonCoder.of()));
PCollection datastream=p
.apply(PubsubIO.Read.named(“从PubSub读取设备数据”)
.topic(String.format(“projects/%s/topics/%s”、options.getSourceProject()、options.getSourceTopic()))
.时间标签(“ts”)
.With Coder(TableRowJSOnCode.of()));

另外:我想您正在使用Dataflow 1.9 SDK?您可能想考虑移动到。您可以在该SDK中找到PubSub的参考。

嗨,Matthias,谢谢您的回复。让我试试看,然后回复您。嗨,Matthias,谢谢您的回复。让我试试,然后回复您。