简体   繁体   English

如何更改 Spring Cloud Stream Kafka binder 的目标?

[英]How to change target of the Spring Cloud Stream Kafka binder?

Using Spring cloud Stream 2.1.4 with Spring Boot 2.1.10, I'm trying to target a local instance of Kafka.使用 Spring 云 Stream 2.1.4 和 Spring Boot 2.1.10,我试图定位 Kafka 的本地实例。 This is an extract of my projetc configuation so far:这是到目前为止我的 projetc 配置的摘录:

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

But the binder keeps on calling a wrong target:但是活页夹不断调用错误的目标:

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

How can can I specify the target if those properties won't do he trick?如果这些属性不会欺骗他,我该如何指定目标? More, I deploy the Kafka instance through a Docker Bitnami image and I'd prefer not to use SSL configuration (see PLAINTEXT protocol) but I'm don't find properties for basic credentials login.此外,我通过 Docker Bitnami 映像部署 Kafka 实例,我不想使用 SSL 配置(请参阅 PLAINTEXT 协议),但我找不到基本凭据登录的属性。 Does anyone know if this is hopeless?有谁知道这是否没有希望?

This is my docker-compose.yml这是我的 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

Thanks in advance提前致谢

The hostname isn't the issue, rahter the advertised listeners protocol//:port mapping that causes the hostname to be advertised, by default. hostname不是问题,而是广告的侦听器protocol//:port映射。 You should change that, rather than the hostname.您应该更改它,而不是主机名。

  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

If you plan on running your code outside of another container, you should advertise localhost in addition to, or instead of the container hostname.如果您计划在另一个容器之外运行您的代码,您应该在容器主机名之外或代替容器主机名上宣传localhost

One year later, my comment still is not been merged into the bitnami README , where I was able to get it working with the following vars (changed to match your deployment) 一年后,我的评论仍未合并到 bitnami README中,我可以在其中使用以下变量(已更改以匹配您的部署)

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

All right: got this to work by looking twice to the "dockerfile" (thx to cricket_007):好的:通过两次查看“dockerfile”(感谢 cricket_007)来实现它:

kafka:
...
    hostname: localhost

For the record: I could get rid of all properties above, default being for Kafka localhost:9092作为记录:我可以摆脱上面的所有属性,默认为 Kafka localhost:9092

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 云 Stream Kafka 无法连接 - Spring Cloud Stream Kafka won't connect 使用Kafka经纪人的Dockerized Spring Cloud Stream服务无法连接到Zookeeper - Dockerized Spring Cloud Stream services with Kafka broker unable to connect to Zookeeper Spring 云 Stream Kafka 与微服务和 Docker-Compose 错误 - Spring Cloud Stream Kafka with Microservices and Docker-Compose Error spring-cloud-starter-stream-kafka不会创建提供给spring.boot.cloud.stream.bindings.output.destination的主题 - spring-cloud-starter-stream-kafka does not creates topic provided to spring.boot.cloud.stream.bindings.output.destination Spring-Cloud-Stream Kafka Azure-提取数据时出现意外错误代码13 - Spring-Cloud-Stream Kafka Azure - Unexpected error code 13 while fetching data 生产者将忽略Kubernetes / Spring Cloud Dataflow流&gt; spring.cloud.stream.bindings.output.destination - Kubernetes/Spring Cloud Dataflow stream > spring.cloud.stream.bindings.output.destination is ignored by producer 如何在 Cloud Foundry 中公开 Kafka 和 Zookeeper 端口 - How to expose Kafka and Zookeeper ports in cloud foundry 在spring cloud中的bootstrap.yml上设置配置文件以定位不同的配置服务器 - Set profile on bootstrap.yml in spring cloud to target different config server 如何在docker上部署spring cloud数据流 - How deploy spring cloud data flow on docker 如何使用 spring cloud config server 和 spring cloud bus with rabbit mq 更新配置? - How to update configurations using spring cloud config server and spring cloud bus with rabbit mq?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM