gpt4 book ai didi

java - Apache 光束 : cannot access Pub/Sub Emulator via docker-compose

转载 作者:行者123 更新时间:2023-12-02 10:10:11 24 4
gpt4 key购买 nike

我构建了一个软件,它使用 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

由于错误提示缺少协议(protocol),在您的情况下预计是http

根据Apache Beam SDK预期为完全限定 URL 的值:

// getPubsubRootUrl
@Default.String(value="https://pubsub.googleapis.com")
@Hidden
java.lang.String getPubsubRootUrl()
// Root URL for use with the Google Cloud Pub/Sub API.

但是,如果您有 Python 背景,您会注意到 Python SDK它使用 gRPC Pythonhere所示仅期望由地址和端口组成的服务器地址

# A snippet from google-cloud-python library.
if os.environ.get("PUBSUB_EMULATOR_HOST"):
kwargs["channel"] = grpc.insecure_channel(
target=os.environ.get("PUBSUB_EMULATOR_HOST")
)
grpc.insecure_channel(target, options=None)
Creates an insecure Channel to a server.

The returned Channel is thread-safe.

Parameters:
target – The server address

关于java - Apache 光束 : cannot access Pub/Sub Emulator via docker-compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55064146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com