【发布时间】:2019-03-08 13:24:22
【问题描述】:
我已经构建了一个软件,它使用 GCP Pub/Sub 作为消息队列,使用 Apache Beam 构建管道,使用 Flask 构建网络服务器。它在生产中运行顺利,但我很难将所有部分与 docker-compose 连接在一起,特别是 Apache Beam 管道。
我已按照Dataflow pipeline and pubsub emulator 将 SO 答案中的 localhost 替换为我的 docker-compose.yaml 中定义的服务名称,从而使管道侦听 GCP Pub/Sub 模拟器:
pubsub_emulator:
build: docker_images/message_queue
ports:
- 8085:8085
webserver:
build: docker_images/webserver
environment:
PUBSUB_EMULATOR_HOST: pubsub_emulator:8085
PUBSUB_PROJECT_ID: my-dev
restart: unless-stopped
ports:
- 8899:8080
depends_on:
- pubsub_emulator
pipeline:
build: docker_images/pipeline
environment:
PUBSUB_EMULATOR_HOST: pubsub_emulator:8085
PUBSUB_PROJECT_ID: my-dev
restart: unless-stopped
depends_on:
- pubsub_emulator
网络服务器能够访问 Pub/Sub 模拟器并生成主题。
但是,管道在启动时失败并显示MalformedURLException:
Caused by: java.lang.IllegalArgumentException: java.net.MalformedURLException: no protocol: pubsub_emulator:8085/v1/projects/my-dev/subscriptions/sync_beam_1702190853678138166
管道的选项看起来不错,我用以下方式定义它们:
final String pubSubEmulatorHost = System.getenv("PUBSUB_EMULATOR_HOST");
BasePipeline.PipeOptions options = PipelineOptionsFactory.fromArgs(args).withValidation()
.as(BasePipeline.PipeOptions.class);
options.as(DataflowPipelineOptions.class).setStreaming(true);
options.as(PubsubOptions.class).setPubsubRootUrl(pubSubEmulatorHost);
Pipeline pipeline = Pipeline.create(options);
有人知道发生了什么以及如何解决它吗?唯一的解决方案是否意味着将模拟器和管道设置在同一个 docker 中?
【问题讨论】:
-
您是否尝试过
http://pubsub_emulator:8085,因为您似乎缺少协议? -
确实,缺少的是
http://。看来python和java SDK的工作方式有一点区别! -
很高兴它成功了!
标签: java docker apache-beam google-cloud-pubsub