江天一鹭飞 2021-07-21 09:47 采纳率: 0%
浏览 417
已结题

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

  • 写回答

1条回答 默认 最新

  • CSDN专家-微编程 2021-07-21 09:51
    关注

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

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月21日
  • 修改了问题 7月21日
  • 修改了问题 7月21日
  • 创建了问题 7月21日

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程