使用springboot在KafkaConsumer中反序列化kafka消息

问题描述 投票:1回答:1

我有一个springboot应用程序,可监听kafka消息并将其转换为对象

@KafkaListener(topics = "test", groupId = "group_id")
public void consume(String message) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        Hostel hostel = objectMapper.readValue(message, Hostel.class);
}

如果可以直接做ti,我会更愿意

@KafkaListener(topics = "test", groupId = "group_id")
public void consume(Hostel hostel) throws IOException { 
}
json spring-boot apache-kafka apache-kafka-streams spring-kafka
1个回答
1
投票
@KafkaListener(topics = "test", groupId = "my.group", containerFactory = "myKafkaFactory") fun genericMessageListener(myRequest: MyRequest, ack: Acknowledgment) { //do Something with myRequest ack.acknowledge() }
热门问题
推荐问题
最新问题