企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# :-: **客户端日志功能** :-: \*\*\*\* 客户端日志记录采用了MQ消息传送数据存储的方式。在需要记录日志的地方发送MQ消息。Kafka消费消息将日志数据存储到数据库 1、定义消息服务 ~~~ @FeignClient(name = "hmall-msg" ,configuration = FeignConfiguration.class) //调用的服务名 public interface MsgApi extends BaseApi { //日志服务 @PostMapping("/sendLog") BaseResp sendLog(@RequestBody String content) ; } ~~~ 2、记录日志发送消息 ~~~ @Resource MsgApi msgApi; msgApi.sendLog("查看商品详情"+pro.getProductName()); ~~~ 3、消息消费&日志存储 ~~~ @Component @Slf4j public class LogMsgListener extends BaseService { @Resource SysLogClientMapper sysLogClientMapper; @KafkaListener(id="HjLog",topics = "HjLog",errorHandler ="consumerAwareErrorHandler" ) public void onMessage( ConsumerRecord r){ log.info("【kafka消息消费】HjLog.....接收到消息key...."+r.key()); log.info("【kafka消息消费】HjLog.....接收到消息value...."+r.value().toString()); Object msg=r.value().toString(); LogClient log= (LogClient) JsonUtil.json2Obj(msg.toString(),LogClient.class); addClientLog(log); } /** * 添加客户日志到数据库 */ public void addClientLog( LogClient logClient){ SysLogClient log=new SysLogClient (); copyProperties(log,logClient); sysLogClientMapper.insert(log); } } ~~~