[英]Apache Beam : cannot access Pub/Sub Emulator via docker-compose
我已經構建了一個軟件,該軟件使用GCP Pub / Sub作為消息隊列,使用Apache Beam來構建管道,使用Flask來構建網絡服務器。 它在生產中運行平穩,但是我很難使所有組件都與docker-compose連接在一起,尤其是Apache Beam管道。
我已經按照Dataflow管道和pubsub模擬器進行操作,通過使用docker-compose.yaml
定義的服務名稱替換SO響應中的localhost
,使管道偵聽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
該網絡服務器能夠訪問發布/訂閱模擬器並生成主題。
但是,管道在啟動時失敗,並帶有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的Python作為顯示這里希望僅由該地址和端口的服務器地址
# 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.