首页 > 解决方案 > Apache Kafka 生产者看不到代理

问题描述

我已经在 PC 上设置了 Apache Kafka 并添加了新主题。当我运行 Kafka 和 Zookeeper 时,它运行没有问题,但是当我尝试发布消息时,没有发送消息,并且我看到以下日志:

WARN 18004 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient   : [Producer clientId=producer-1] Connection to node -1 (/127.0.0.1:9092) could not be established. Broker may not be available.
WARN 18004 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient   : [Producer clientId=producer-1] Bootstrap broker 127.0.0.1:9092 (id: -1 rack: null) disconnected

我的卡夫卡配置是:

@Configuration
public class KafkaProducerConfig {

    private final static String SERVER_ADDRESS = "127.0.0.1:9092";

    @Bean
    public ProducerFactory<String, String> producerFactory() {
        Map<String, Object> configProps = new HashMap<>();
        configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, SERVER_ADDRESS);
        configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
        configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);

        return new DefaultKafkaProducerFactory<>(configProps);
    }

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

}

我的 server.properties 是:

############################# Server Basics #############################
broker.id=0
############################# Socket Server Settings #############################
listeners=PLAINTEXT://127.0.0.1:9092
    num.network.threads=3
    num.io.threads=8
    socket.send.buffer.bytes=102400
    socket.receive.buffer.bytes=102400
    socket.request.max.bytes=104857600
    ############################# Log Basics #############################
    log.dirs=./tmp/kafka-logs
    num.partitions=1
    num.recovery.threads.per.data.dir=1
    ############################# Internal Topic Settings  #############################
    offsets.topic.replication.factor=1
    transaction.state.log.replication.factor=1
    transaction.state.log.min.isr=1
    ############################# Log Retention Policy #############################
    log.retention.hours=168
    log.segment.bytes=1073741824
    log.retention.check.interval.ms=300000
    ############################# Zookeeper #############################
    zookeeper.connect=localhost:2181
    # Timeout in ms for connecting to zookeeper
    zookeeper.connection.timeout.ms=18000
    ############################# Group Coordinator Settings #############################
    group.initial.rebalance.delay.ms=0

问题是什么?我该如何解决?

标签: javaspring-bootapache-kafkamicroservicesspring-kafka

解决方案


推荐阅读