简体   繁体   English

我的 spring 应用程序无法连接到 kafka 代理

[英]My spring app can't connect to kafka broker

I'm trying to coonect my spring boot application to Kafka topic, but it seams that spring is trying to connect to to localhost and not docker ip, because I'm using docker on windows. I'm trying to coonect my spring boot application to Kafka topic, but it seams that spring is trying to connect to to localhost and not docker ip, because I'm using docker on windows. This is Kafka configuration class on spring:这是 spring 上的 Kafka 配置 class:

@Configuration
public class KafkaConfig {

@Bean
public ProducerFactory<String,String> producerFactory()
{
    Map<String,Object> config = new HashMap<>();

    config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.99.100:9092");
    config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
    config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);

    return  new DefaultKafkaProducerFactory<>(config);
}

@Bean
public KafkaTemplate kafkaTemplate()
{
    return  new KafkaTemplate<>(producerFactory());
}
}

My docer-compose is: version: '2'我的文档编写是:版本:'2'

services:
   zookeeper:
      image: confluentinc/cp-zookeeper:latest
      ports:
      - 2181:2181
      environment:
         ZOOKEEPER_CLIENT_PORT: 2181
         ZOOKEEPER_TICK_TIME: 2000
   kafka:
     image: confluentinc/cp-kafka:latest
     ports:
      - 9092:9092
     depends_on:
       - zookeeper
     environment:
        KAFKA_BROKER_ID: 1
        KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
        KAFKA_CREATE_TOPICS: "scraper:2:4,Topic2:1:1:compact"
        KAFKA_ADVERTISED_LISTENERS: LISTENER_INSIDE://kafka:29092,LISTENER_HOST://192.168.99.100:9092
        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_INSIDE:PLAINTEXT,LISTENER_HOST:PLAINTEXT
        KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_INSIDE
        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
        KAFKA_HEAP_OPTS: " -Xmx256m -Xms256m"

The error is:错误是:

Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

is there another configuration missing in my docker compose or spring properties?我的 docker compose 或 spring 属性中是否缺少其他配置?

There's no reason to connect to "Docker IP" if you use port forwarding correctly如果您正确使用端口转发,则没有理由连接到“Docker IP”

localhost:9092 should work fine, but it seems your code isn't using the settings you've provided anyway localhost:9092应该可以正常工作,但是您的代码似乎没有使用您提供的设置

Note: KAFKA_CREATE_TOPICS does not do anything for Confluent images注意: KAFKA_CREATE_TOPICS对 Confluent 图像没有任何作用

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

相关问题 Spring 应用程序无法连接到 Kafka 代理 - Spring application cannot connect to a Kafka broker 为什么App Engine无法使用我的Spring Boot应用程序连接到Cloud SQL? - Why App Engine can't connect to Cloud SQL with my Spring Boot app? Angular web 应用程序无法正确连接到我的 Spring 启动应用程序 ZDB974238714CA8DE1434A7CE1DFZ83A - Angular web app can't properly connect to my Spring Boot app API Spring Kafka - 代理重新连接事件 - Spring Kafka - broker reconnect event 我的Spring Boot应用程序的新版本无法连接到mysql - New version of my spring boot app's can't connect to mysql 在 Spring 启动(云应用程序)中无法连接到 Oracle DB - Can't connect to Oracle DB in Spring Boot (Cloud App) 无法将 MongoDB Atlas 集群连接到 Spring 启动应用程序 - Can't connect MongoDB Atlas cluster to a Spring boot app Spring 云 Stream Binder Kafka 代理不可用 - Spring Cloud Stream Binder Kafka broker is not available 当没有 kafka 代理运行时,如何出于开发目的禁用 Spring Cloud 流? - How can I disable spring cloud stream for development purpose when there are not kafka broker running? 无法为多个消费者订阅 Spring Kafka 测试嵌入式 Kafka 代理 - Cannot subscribe multiple consumers to Spring Kafka Test embedded Kafka broker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM