【发布时间】:2019-04-29 16:20:07
【问题描述】:
我正在尝试使用 DirectRunner 运行一个简单的 Apache Beam 管道,该管道从 Pub/Sub 订阅中读取数据并将消息写入磁盘。
当我在 GCP 上运行管道时,它运行良好,但是当我尝试在本地 Pub/Sub 模拟器上运行它时,它似乎没有做任何事情。
我正在使用扩展 org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions 类的自定义 Options 类。
public interface Options extends PubsubOptions {
@Description("Pub/Sub subscription to read the input from")
@Required
ValueProvider<String> getInputSubscription();
void setInputSubscription(ValueProvider<String> valueProvider);
}
管道很简单
pipeline
.apply("Read Pub/Sub Messages", PubsubIO.readMessagesWithAttributes()
.fromSubscription(options.getInputSubscription()))
.apply("Add a fixed window", Window.into(FixedWindows.of(Duration.standardSeconds(WINDOW_SIZE))))
.apply("Convert Pub/Sub To String", new PubSubMessageToString())
.apply("Write Pub/Sub messages to local disk", new WriteOneFilePerWindow());
管道使用以下选项执行
mvn compile exec:java \
-Dexec.mainClass=DefaultPipeline \
-Dexec.cleanupDaemonThreads=false \
-Dexec.args=" \
--project=my-project \
--inputSubscription=projects/my-project/subscriptions/my-subscription \
--pubsubRootUrl=http://127.0.0.1:8681 \
--runner=DirectRunner"
我正在使用this Pub/Sub 模拟器 docker 映像并使用以下命令执行它:
docker run --rm -ti -p 8681:8681 -e PUBSUB_PROJECT1=my-project,topic:my-subscription marcelcorso/gcloud-pubsub-emulator:latest
是否需要更多配置才能完成这项工作?
【问题讨论】:
-
您能否提供在针对 GCP 运行管道时使用的类似
mvn命令?仅仅是没有提供 pubsubRootUrl=127.0.0.1:8681 作为参数吗? -
是的,没有 pubsubRootUrl=127.0.0.1:8681 参数也一样
标签: docker apache-beam google-cloud-pubsub