nvps增强检索工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. package com.bw.search.process;
  2. import java.util.Map;
  3. import org.springframework.kafka.annotation.KafkaListener;
  4. import org.springframework.stereotype.Component;
  5. import com.alibaba.fastjson.JSONObject;
  6. import com.bw.search.cache.ConfigCache;
  7. import com.bw.search.entity.Constants;
  8. import lombok.extern.slf4j.Slf4j;
  9. /**
  10. * 接口响应结果操作类
  11. * @author jian.mao
  12. * @date 2023年7月6日
  13. * @description
  14. */
  15. @Component
  16. @Slf4j
  17. public class ResultSendQueue {
  18. /**
  19. * kafka读取结果写入队列
  20. * @param message
  21. */
  22. @KafkaListener(topics = "#{kafkaConfig.getKafkaTopic()}")
  23. public void consumeMessage(String message) {
  24. // 处理接收到的消息逻辑
  25. try {
  26. Map<String, Object> result = JSONObject.parseObject(message);
  27. String key = result.get(Constants.ID).toString();
  28. ConfigCache.baseResult.put(key, result);
  29. ConfigCache.searchResult.put(key, result);
  30. log.info("消费知识:{}",key);
  31. } catch (Exception e) {
  32. log.error("结果集json转换失败,result:{},\n",message,e);
  33. }
  34. }
  35. }