简体   繁体   中英

Spring Cloud Stream Kafka won't connect

I'm using this docker compose:

version: '2'
services:

  zookeeper:
    image: confluentinc/cp-zookeeper:4.1.1
    hostname: zookeeper
    ports:
    - "32181:32181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 32181
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_SYNC_LIMIT: 2

  kafka:
    image: confluentinc/cp-kafka:4.1.1
    hostname: kafka
    ports:
    - "29092:29092"
    depends_on:
    - zookeeper
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

And my properties are:

spring.cloud.stream.bindings.event.binder=event-binder
spring.cloud.stream.bindings.event.destination=event    

spring.cloud.stream.binders.event-binder.type=kafka

spring.cloud.stream.kafka.binder.brokers=localhost:29092
spring.cloud.stream.kafka.binder.zkNodes=localhost:32181

But I'm receiving this error:

9:54:14.534 [main] INFO  o.a.kafka.common.utils.AppInfoParser - Kafka version : 2.0.1
19:54:14.534 [main] INFO  o.a.kafka.common.utils.AppInfoParser - Kafka commitId : fa14705e51bd2ce5
19:54:14.576 [kafka-admin-client-thread | adminclient-1] WARN  o.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Connection to node -1 could not be established. Broker may not be available.
19:54:14.679 [kafka-admin-client-thread | adminclient-1] WARN  o.apache.kafka.clients.NetworkClient - [AdminClient clientId=adminclient-1] Connection to node -1 could not be established. Broker may not be available.
19:

My spring boot version is 2.1.4.RELEASE and my spring cloud version is Greenwich.SR1.

Thanks in advance!

With that configuration, I think you need

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:29092

You should configuration with:

spring.cloud.stream.kafka.binder.brokers=PLAINTEXT://your host:29092 spring.cloud.stream.kafka.binder.zkNodes=PLAINTEXT://your host:29092

In file docker-compose.yml you should have: KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://your host:29092 If connect successful in docker and you have run successful in spring cloud stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM