所以我最近才开始使用Kafka,出于某种奇怪的原因,尽管kafka和zookeeper服务器容器按照文档中的预期运行并通过使用docker ps命令运行。我不断收到此特定错误
我已经尝试使用不同的配置来解决此问题大约一个星期,但它仍然不断给我带来错误的无休止循环。
我遵循了这两个教程: https://rmoff.net/2018/08/02/kafka-listeners-explained/和https://www.youtube.com/watch?v=-0vrqMMGQbc
docker-compose up运行得很好,并且代理启动,但是当我启动mvn spring-boot:run命令时,它将失败。
我也尝试通过本地计算机更改地址,但仍然没有任何更改。希望能有所帮助
这是我的docker-compose.yml
version: '3.2'
services:
zookeeper:
container_name: zookeeper
image: wurstmeister/zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
kafka:
container_name: kafka
image: wurstmeister/kafka
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: INTERNAL://:19092,EXTERNAL://:9092
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:19092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
depends_on:
- zookeeper
volumes:
- /var/run/docker.sock:/var/run/docker.sock
这是我的应用程序。yml
# Server
server:
port: 8090
# Spring Kafka & H2
spring:
autoconfigure:
exclude: org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
kafka:
bootstrap-servers: localhost:9092
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:api;MODE=MySQL
username: api
password: root
driverClassName: org.h2.Driver
result:
topic.name: result
# Keycloak
keycloak:
auth-server-url: http://localhost:8080/auth
realm: demo
resource: demo-api
enabled: false
public-client: false
bearer-only : true
principal-attribute: preferred_username
allow-any-hostname: true
# credentials:
# secret:
# Logging
logging:
level:
org.springframework.web: DEBUG
org.hibernate: DEBUG
org: INFO
com.API.demo.Controllers: DEBUG
config: src/main/resources/logback-spring.xml
file:
path: logs/log
答案 0 :(得分:1)
广告监听器的定义不正确
代替
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:19092
您需要
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka:19092,EXTERNAL://localhost:9092
还请注意,如果您希望经纪人自动创建主题,则需要设置
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'