Apache Beam:找不到 DataflowRunner

Apache Beam: Cannot find DataflowRunner

我正在尝试 运行 一个管道,我能够 运行 在 Google 云数据流上成功 DirectRunner。当我执行这个 Maven 命令时:

mvn compile exec:java \
    -Dexec.mainClass=com.example.Pipeline \
    -Dexec.args="--project=project-name \
    --stagingLocation=gs://bucket-name/staging/ \
    ... custom arguments ...
    --runner=DataflowRunner"

我收到以下错误:

No Runner was specified and the DirectRunner was not found on the classpath.
[ERROR] Specify a runner by either:
[ERROR]     Explicitly specifying a runner by providing the 'runner' property
[ERROR]     Adding the DirectRunner to the classpath
[ERROR]     Calling 'PipelineOptions.setRunner(PipelineRunner)' directly

我故意从我的 pom.xml 中删除了 DirectRunner 并添加了这个:

<dependency>
    <groupId>org.apache.beam</groupId>
    <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
    <version>2.0.0</version>
    <scope>runtime</scope>
</dependency>

我继续删除 <scope> 标签,然后调用 options.setRunner(DataflowRunner.class),但没有帮助。从 DataflowPipelineOptions 扩展我自己的 PipelineOptions 接口也没有解决问题。

看起来它以我无法调试的方式忽略了 runner 选项。

更新:这是完整的pom.xml,以防有帮助:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>dataflow</artifactId>
    <version>0.1</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.beam</groupId>
            <artifactId>beam-sdks-java-core</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.beam</groupId>
            <artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
            <version>2.0.0</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.beam</groupId>
            <artifactId>beam-sdks-java-io-jdbc</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.beam</groupId>
            <artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.1.4.jre7</version>
        </dependency>
    </dependencies>
</project>

您使用的是哪个 Dataflow SDK 版本?

如果您使用的是 Dataflow 2.X,则可以使用 DirectRunner

在 Dataflow 1.X 中,您可以使用 DirectPipelineRunner

您还可以看到 Getting started instructions here 建议的 DataflowRunner 和 BlockingDataflowRunner(取决于您的版本)。如果可以的话,我建议先尝试让它工作。

忘记将我的 PipelineOptions 实例作为参数传递给 Pipeline.create() 方法是我出现问题的原因。

PipelineOptionsFactory.register(MyOptions.class);
MyOptions options = PipelineOptionsFactory.fromArgs(args).withValidation().as(MyOptions.class);
Pipeline pipeline = Pipeline.create(options); // Don't forget the options argument.
...
pipeline.run();