Commit 3ebd3776 authored by 赵啸非's avatar 赵啸非

异常日志前端展示添加

parent e7f2c60a
...@@ -96,6 +96,12 @@ public class RabbitConfig { ...@@ -96,6 +96,12 @@ public class RabbitConfig {
SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) { SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
// 创建 SimpleRabbitListenerContainerFactory 对象 // 创建 SimpleRabbitListenerContainerFactory 对象
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setAfterReceivePostProcessors(m -> {
m.getMessageProperties().setContentType("application/json");
return m;
});
configurer.configure(factory, connectionFactory); configurer.configure(factory, connectionFactory);
// 额外添加批量消费的属性 // 额外添加批量消费的属性
factory.setBatchListener(true); factory.setBatchListener(true);
......
...@@ -37,15 +37,15 @@ import java.util.stream.Collectors; ...@@ -37,15 +37,15 @@ import java.util.stream.Collectors;
**/ **/
@Slf4j @Slf4j
@Component @Component
//@RabbitListener(queues = QueueKey.ACCESS_LOG_QUEUE, @RabbitListener(queues = QueueKey.ACCESS_LOG_QUEUE,
// containerFactory = "consumerBatchContainerFactory") containerFactory = "consumerBatchContainerFactory")
@RabbitListener(queues = QueueKey.ACCESS_LOG_QUEUE) //@RabbitListener(queues = QueueKey.ACCESS_LOG_QUEUE)
public class AccessMessageConsumerListener { public class AccessMessageConsumerListener {
@Autowired @Autowired
private AccessLogService accessLogService; private AccessLogService accessLogService;
@RabbitHandler //@RabbitHandler
public void onMessage(AccessLogEntity entity) throws Exception { public void onMessage(AccessLogEntity entity) throws Exception {
log.info("[Access onMessage single]"); log.info("[Access onMessage single]");
...@@ -55,34 +55,20 @@ public class AccessMessageConsumerListener { ...@@ -55,34 +55,20 @@ public class AccessMessageConsumerListener {
accessLogService.save(entity,null); accessLogService.save(entity,null);
} }
//@RabbitHandler @RabbitHandler
public void onMessage(@Payload List<String> messages) throws Exception { public void onMessage(@Payload List<String> messages) throws Exception {
log.info("[Access onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getName() + Thread.currentThread().getId(), messages.size()); log.info("[Access onMessage][线程编号:{} 消息数量:{}]", Thread.currentThread().getName() + Thread.currentThread().getId(), messages.size());
// if(messages instanceof ArrayList<String>){
//
// }
if ( messages.stream().noneMatch((o -> !(o instanceof String)))) {
log.info("都匹配");
}else{
log.info("存在类型不匹配");
}
List<AccessLogEntity> collect = messages.stream().map(message -> { List<AccessLogEntity> collect = messages.stream().map(message -> {
try { try {
AccessLogEntity entity =null; AccessLogEntity entity =null;
if(message instanceof String){
log.info("message:{}", message); log.info("message:{}", message);
entity = JSON.parseObject(message, AccessLogEntity.class); entity = JSON.parseObject(message, AccessLogEntity.class);
entity.setId(IdUtil.getSnowflake(0, 1).nextId()); entity.setId(IdUtil.getSnowflake(0, 1).nextId());
entity.setCreateUserId(1L); entity.setCreateUserId(1L);
entity.setCreateTime(new Date()); entity.setCreateTime(new Date());
}else{
// entity=(AccessLogEntity)message;
}
//String json = JSONUtil.formatJsonStr(new String(message, StandardCharsets.UTF_8)); //String json = JSONUtil.formatJsonStr(new String(message, StandardCharsets.UTF_8));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment