使用quarkus&smallrye时更改kafka主机和端口

cidc1ykv  于 2021-06-04  发布在  Kafka
关注(0)|答案(2)|浏览(439)

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

mm5n2pyu

mm5n2pyu1#

指南似乎假设代码没有在容器中运行
如果您的服务也在容器中运行,则需要在kafka容器上设置此选项

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
dldeef67

dldeef672#

下面是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

相关问题