0

当我需要通过 docker-compose 运行 Kafka 主机和端口时,我无法更改它。我想使用相同的 docker-compose 来运行我的服务和 Kafka。所以我需要更改 Kafka 主机。

我试图提供以下环境变量但没有运气:mp.messaging.outgoing.my-channel.bootstrap.servers="Kafka:9092"

我在 Quarkus/Kafka 指南中使用了相同的 docker-compose: https ://quarkus.io/guides/kafka-guide

4

2 回答 2

1

该指南似乎假定代码未在容器中运行

如果您的服务也在容器中运行,则需要在 Kafka 容器上进行设置

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
于 2019-10-23T02:31:55.050 回答
1

这是一个示例 docker-compose.yaml 文件。

version: '2'

services:

  zookeeper:
    image: strimzi/kafka:0.20.0-kafka-2.6.0
    command: [
      "sh", "-c",
      "bin/zookeeper-server-start.sh config/zookeeper.properties"
    ]
    ports:
      - "2181:2181"
    environment:
      LOG_DIR: /tmp/logs

  kafka:
    image: strimzi/kafka:0.20.0-kafka-2.6.0 
    command: [
      "sh", "-c",
      "bin/kafka-server-start.sh config/server.properties --override 
listeners=$${KAFKA_LISTENERS} --override 
advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override 
zookeeper.connect=$${KAFKA_ZOOKEEPER_CONNECT}"
    ]
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
    environment:
      LOG_DIR: "/tmp/logs"
      # Dev GQ - Laptop
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://172.23.240.1:9092
      # AWS Pre-Prod  
      #KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://11.122.200.229:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

这是一个示例 Quarkus application.properties 文件,其中 kafka 引导服务器配置为 docker-compose.yaml 中的广告侦听器。这是另一个 docker 映像上的本地内部。

# Configure the SmallRye Kafka connector
# Dev GQ - Laptop
mp.messaging.connector.smallrye-kafka.bootstrap.servers=172.23.240.1:9092
# AWS Pre-Prod
#mp.messaging.connector.smallrye-kafka.bootstrap.servers=11.122.200.229:9092
quarkus.kafka.health.enabled=true

# Configure the Kafka sink (we write to it)
mp.messaging.outgoing.generated-price.connector=smallrye-kafka
mp.messaging.outgoing.generated-price.topic=prices
mp.messaging.outgoing.generated-price.value.serializer=org.apache.kafka.common.serialization.IntegerSerializer

# Configure the Kafka source (we read from it)
mp.messaging.incoming.prices.connector=smallrye-kafka
mp.messaging.incoming.prices.topic=prices
# ..... more codes 
于 2020-12-08T19:58:50.897 回答