SpringBoot+kafka无法连接

在虚拟机中启动zookeeper和kafka,可以再控制台中消费,防火墙关闭,端口正常,但是项目启动报错。

SpringBoot项目配置:

        <!--Kafka依赖-->
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
        </dependency>
spring:
  kafka:
    bootstrap-servers: 192.168.43.22:9092
    # 消费者
    consumer:
      group-id: te465
      auto-offset-reset: latest
      enable-auto-commit: true
      auto-commit-interval: 100
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      #max-poll-records: 10
    # 生产者
    producer:
      acks: all
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
@Component
public class kafkaConsumer {

    // 消费监听
    @KafkaListener(topics = {"topic2"})
    public void onMessage1(ConsumerRecord<?, ?> record){
        // 消费的哪个topic、partition的消息,打印出消息内容
        System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value());
    }

项目报错:

2021-07-21 09:42:29.051  WARN 2348 --- [ntainer#0-0-C-1] org.apache.kafka.clients.NetworkClient   : [Consumer clientId=consumer-te465-1, groupId=te465] Bootstrap broker 192.168.43.22:9092 (id: -1 rack: null) disconnected

img
虚拟机中:

[root@localhost bin]# ./kafka-topics.sh --zookeeper 192.168.43.22:2181 --list
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
topic
topic1
topic2
[root@localhost bin]# ./kafka-console-consumer.sh  --zookeeper 192.168.43.22:2181  --topic topic1 --from-beginning
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
[2021-07-21 10:11:38,161] INFO Closing socket connection to /192.168.43.22. (kafka.network.Processor)
hello
exit
why

img

错误的请求类型,建议你将你的问题重新编辑一下,将你的连接kafka代码粘贴出来