[英]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.