使用Quarkus和SmallRye时更改kafka主机和端口

时间:2019-10-22 12:16:26

标签: docker apache-kafka quarkus smallrye-reactive-messaging

当我需要通过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

2 个答案:

答案 0 :(得分:1)

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

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

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092

答案 1 :(得分: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文件,在docker-compose.yaml中将kafka引导服务器配置为公告的侦听器。这是另一个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