如何改变Kafka活页夹的目标?

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

使用springcloudstream2.1.4和springboot2.1.10,我试图针对kafka的一个本地示例。这是我到目前为止项目配置的摘录:

spring.kafka.bootstrap-servers=PLAINTEXT://localhost:9092
spring.kafka.streams.bootstrap-servers=PLAINTEXT://localhost:9092
spring.cloud.stream.kafka.binder.brokers=PLAINTEXT://localhost:9092
spring.cloud.stream.kafka.binder.zkNodes=localhost:2181
spring.cloud.stream.kafka.streams.binder.brokers=PLAINTEXT://localhost:9092
spring.cloud.stream.kafka.streams.binder.zkNodes=localhost:2181

但是宾德一直在说一个错误的目标:

java.io.IOException: Can't resolve address: kafka.example.com:9092

如果那些属性不起作用,我怎么能指定目标呢?此外,我通过docker bitnami映像部署kafka示例,我不希望使用ssl配置(请参阅明文协议),但我不希望找到基本凭据登录的属性。有人知道这是不是没有希望了吗?
这是我的docker-compose.yml

version: '3'
services: 
  zookeeper:
    image: bitnami/zookeeper:latest
    container_name: zookeeper
    environment:
      - ZOO_ENABLE_AUTH=yes
      - ZOO_SERVER_USERS=kafka
      - ZOO_SERVER_PASSWORDS=kafka_password
    networks:
      - kafka-net
  kafka:
    image: bitnami/kafka:latest
    container_name: kafka
    hostname: kafka.example.com
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_ZOOKEEPER_USER=kafka
      - KAFKA_ZOOKEEPER_PASSWORD=kafka_password
    networks:
      - kafka-net
networks:
  kafka-net:
    driver: bridge

提前谢谢

biswetbf

biswetbf1#

好吧:看了两遍“dockerfile”(thx to cricket\ u007)就成功了:

kafka:
...
    hostname: localhost

作为记录:我可以去掉上面所有的属性,默认为Kafkalocalhost:9092

x8goxv8g

x8goxv8g2#

这个 hostname 问题不在这里吗,rahter广告的听众们 protocol//:port 默认情况下,导致播发主机名的Map。您应该更改它,而不是主机名。

kafka:
    image: bitnami/kafka:latest
    container_name: kafka
    hostname: kafka.example.com # <--- Here's what you are getting in the request
    ...
    environment:
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092 # <--- This returns the hostname to the clients

如果您计划在另一个容器之外运行您的代码,您应该公布 localhost 除了容器主机名之外,或者替代容器主机名。
一年后,我的评论仍然没有被合并到bitnami自述中,在那里我可以让它与以下变量一起工作(更改以匹配您的部署)

KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_CFG_LISTENERS=PLAINTEXT://:29092,PLAINTEXT_HOST://:9092
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka.example.com:29092,PLAINTEXT_HOST://localhost:9092

相关问题