package com.bw.search.process; import java.util.Map; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSONObject; import com.bw.search.cache.ConfigCache; import com.bw.search.entity.Constants; import lombok.extern.slf4j.Slf4j; /** * 接口响应结果操作类 * @author jian.mao * @date 2023年7月6日 * @description */ @Component @Slf4j public class ResultSendQueue { /** * kafka读取结果写入队列 * @param message */ @KafkaListener(topics = "#{kafkaConfig.getKafkaTopic()}") public void consumeMessage(String message) { // 处理接收到的消息逻辑 try { Map result = JSONObject.parseObject(message); String key = result.get(Constants.ID).toString(); ConfigCache.baseResult.put(key, result); ConfigCache.searchResult.put(key, result); log.info("消费知识:{}",key); } catch (Exception e) { log.error("结果集json转换失败,result:{},\n",message,e); } } }