feature(improve) - 优化 MQ 记录日志的逻辑

This commit is contained in:
wangli 2026-03-23 16:33:10 +08:00
parent e5f1ce70c3
commit 84c38e0647
3 changed files with 18 additions and 5 deletions

View File

@ -19,8 +19,9 @@ public class MqLogEvent extends ApplicationEvent {
private String messageBody;
private String traceId;
private MqLogEventType eventType;
private String targetType;
public MqLogEvent(String uniqueId, String messageId, String mqTag, String mqKey, String messageBody, String traceId, MqLogEventType eventType) {
public MqLogEvent(String uniqueId, String messageId, String mqTag, String mqKey, String messageBody, String traceId, MqLogEventType eventType, String targetType) {
super(uniqueId);
this.uniqueId = uniqueId;
this.messageId = messageId;
@ -29,6 +30,7 @@ public class MqLogEvent extends ApplicationEvent {
this.messageBody = messageBody;
this.traceId = traceId;
this.eventType = eventType;
this.targetType = targetType;
}
public String getUniqueId() {
@ -86,4 +88,12 @@ public class MqLogEvent extends ApplicationEvent {
public void setEventType(MqLogEventType eventType) {
this.eventType = eventType;
}
public String getTargetType() {
return targetType;
}
public void setTargetType(String targetType) {
this.targetType = targetType;
}
}

View File

@ -35,7 +35,10 @@ public class MqLogListener implements ApplicationListener<MqLogEvent> {
if (!refreshProperties.getMqLogEnable()) {
return;
}
ListUtils.emptyIfNull(refreshProperties.getSupportedMqLogProcessDefinitionKeys());
if (!ListUtils.emptyIfNull(refreshProperties.getSupportedMqLogProcessDefinitionKeys()).contains(event.getTargetType())) {
log.info("mq_log_process_definition_not_found: {}", event.getTargetType());
return;
}
switch (event.getEventType()) {
case INSERT:
insert(buildMqLogEntity(event));

View File

@ -86,7 +86,7 @@ public class RocketMqEventConfiguration {
MqLogEvent mqLogEvent = new MqLogEvent(event.getEventId(), null,
event.getEventName(), event.getShardingKey(),
event.toPrettyJsonString(), TraceUtils.getOrCreateTraceId(),
MqLogEventType.INSERT);
MqLogEventType.INSERT, event.getTargetType());
log.info("mq_send_Before: {}, uniqueId: {}", event.getShardingKey(), event.getEventId());
applicationEventPublisher.publishEvent(mqLogEvent);
};
@ -105,7 +105,7 @@ public class RocketMqEventConfiguration {
MqLogEvent mqLogEvent = new MqLogEvent(event.getEventId(), messageId,
event.getEventName(), event.getShardingKey(),
event.toPrettyJsonString(), TraceUtils.getOrCreateTraceId(),
MqLogEventType.UPDATE);
MqLogEventType.UPDATE, event.getTargetType());
log.info("mq_send_after: {}, uniqueId: {}, messageId: {}", event.getShardingKey(), event.getEventId(), messageId);
applicationEventPublisher.publishEvent(mqLogEvent);
};
@ -122,7 +122,7 @@ public class RocketMqEventConfiguration {
return (event, context) -> {
MqLogEvent mqLog = new MqLogEvent(event.getEventId(), null, event.getEventName(),
event.getShardingKey(), event.toPrettyJsonString(), TraceUtils.getOrCreateTraceId(),
MqLogEventType.DELETE);
MqLogEventType.DELETE, event.getTargetType());
log.info("mq_transaction_rollback: {}, uniqueId: {}", event.getShardingKey(), event.getEventId());
applicationEventPublisher.publishEvent(mqLog);
};