Springboot整合kafka简单使用
参考文献
Springboot整合kafka简单使用_springboot kafka-CSDN博客
linux中的kafka必须写 ip addr中的ip 不然Windows连接不上 注意下
package com.atguigu.yygh.cmn.config;import com.alibaba.fastjson.JSON;
import com.atguigu.yygh.cmn.controller.MessageVO;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;import java.util.Date;
@Component
public class recvViewUserMessage1 {@KafkaListener(topics = "viewUserTopic")public void recvViewUserMessage(String message, Acknowledgment acknowledgment) {//--1 接收消息MessageVO messageVo = JSON.parseObject(message, MessageVO.class);System.out.println(messageVo + "我终于收到了 哈哈哈");//--4 手动确认消息//手动确认消费完成,通知 Kafka 服务器该消息已经被处理。acknowledgment.acknowledge();}}