forked from sfms3.0/sfms3.0
26 changed files with 462 additions and 52 deletions
@ -1,6 +0,0 @@ |
|||||
/** |
|
||||
* 提供 POJO 类的实体转换 |
|
||||
* |
|
||||
* 目前使用 MapStruct 框架 |
|
||||
*/ |
|
||||
package com.win.module.infra.convert; |
|
@ -0,0 +1,32 @@ |
|||||
|
package com.win.module.infra.mq.consumer.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessageListener; |
||||
|
import com.win.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; |
||||
|
import com.win.module.infra.convert.logger.ApiAccessLogConvert; |
||||
|
import com.win.module.infra.mq.message.logger.ApiAccessLogMessage; |
||||
|
import com.win.module.infra.service.logger.ApiAccessLogService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* 访问日志消费端 |
||||
|
* |
||||
|
* @author zzf |
||||
|
*/ |
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class ApiAccessLogConsumer extends AbstractStreamMessageListener<ApiAccessLogMessage> { |
||||
|
|
||||
|
@Resource |
||||
|
private ApiAccessLogService apiAccessLogService; |
||||
|
|
||||
|
@Override |
||||
|
public void onMessage(ApiAccessLogMessage message) { |
||||
|
log.info("[onMessage][消息内容({})]", message); |
||||
|
ApiAccessLogCreateReqDTO apiAccessLog = ApiAccessLogConvert.INSTANCE.convert(message); |
||||
|
apiAccessLogService.createApiAccessLog(apiAccessLog); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.win.module.infra.mq.consumer.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessageListener; |
||||
|
import com.win.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; |
||||
|
import com.win.module.infra.convert.logger.ApiErrorLogConvert; |
||||
|
import com.win.module.infra.mq.message.logger.ApiErrorLogMessage; |
||||
|
import com.win.module.infra.service.logger.ApiErrorLogService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* 访问日志消费端 |
||||
|
* |
||||
|
* @author zzf |
||||
|
*/ |
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class ApiErrorLogConsumer extends AbstractStreamMessageListener<ApiErrorLogMessage> { |
||||
|
|
||||
|
@Resource |
||||
|
private ApiErrorLogService apiErrorLogService; |
||||
|
|
||||
|
@Override |
||||
|
public void onMessage(ApiErrorLogMessage message) { |
||||
|
log.info("[onMessage][消息内容({})]", message); |
||||
|
ApiErrorLogCreateReqDTO apiAccessLog = ApiErrorLogConvert.INSTANCE.convert(message); |
||||
|
apiErrorLogService.createApiErrorLog(apiAccessLog); |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,4 +0,0 @@ |
|||||
/** |
|
||||
* 消息队列的消费者 |
|
||||
*/ |
|
||||
package com.win.module.infra.mq.consumer; |
|
@ -0,0 +1,32 @@ |
|||||
|
package com.win.module.infra.mq.consumer.trends; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessageListener; |
||||
|
import com.win.module.infra.api.trends.dto.TrendsCreateReqDTO; |
||||
|
import com.win.module.infra.convert.trends.TrendsConvert; |
||||
|
import com.win.module.infra.mq.message.trends.TrendsMessage; |
||||
|
import com.win.module.infra.service.trends.TrendsService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* 访问日志消费端 |
||||
|
* |
||||
|
* @author zzf |
||||
|
*/ |
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class TrendsConsumer extends AbstractStreamMessageListener<TrendsMessage> { |
||||
|
|
||||
|
@Resource |
||||
|
private TrendsService trendsService; |
||||
|
|
||||
|
@Override |
||||
|
public void onMessage(TrendsMessage message) { |
||||
|
log.info("[onMessage][消息内容({})]", message); |
||||
|
TrendsCreateReqDTO trendsCreateReqDTO = TrendsConvert.INSTANCE.convert(message); |
||||
|
trendsService.createTrends(trendsCreateReqDTO); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,89 @@ |
|||||
|
package com.win.module.infra.mq.message.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessage; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* 短信发送消息 |
||||
|
* |
||||
|
* @author 闻荫源码 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class ApiAccessLogMessage extends AbstractStreamMessage { |
||||
|
|
||||
|
/** |
||||
|
* 链路追踪编号 |
||||
|
*/ |
||||
|
private String traceId; |
||||
|
/** |
||||
|
* 用户编号 |
||||
|
*/ |
||||
|
private Long userId; |
||||
|
/** |
||||
|
* 应用名 |
||||
|
*/ |
||||
|
@NotNull(message = "应用名不能为空") |
||||
|
private String applicationName; |
||||
|
|
||||
|
/** |
||||
|
* 请求方法名 |
||||
|
*/ |
||||
|
@NotNull(message = "http 请求方法不能为空") |
||||
|
private String requestMethod; |
||||
|
/** |
||||
|
* 访问地址 |
||||
|
*/ |
||||
|
@NotNull(message = "访问地址不能为空") |
||||
|
private String requestUrl; |
||||
|
/** |
||||
|
* 请求参数 |
||||
|
*/ |
||||
|
@NotNull(message = "请求参数不能为空") |
||||
|
private String requestParams; |
||||
|
/** |
||||
|
* 用户 IP |
||||
|
*/ |
||||
|
@NotNull(message = "ip 不能为空") |
||||
|
private String userIp; |
||||
|
/** |
||||
|
* 浏览器 UA |
||||
|
*/ |
||||
|
@NotNull(message = "User-Agent 不能为空") |
||||
|
private String userAgent; |
||||
|
|
||||
|
/** |
||||
|
* 开始请求时间 |
||||
|
*/ |
||||
|
@NotNull(message = "开始请求时间不能为空") |
||||
|
private LocalDateTime beginTime; |
||||
|
/** |
||||
|
* 结束请求时间 |
||||
|
*/ |
||||
|
@NotNull(message = "结束请求时间不能为空") |
||||
|
private LocalDateTime endTime; |
||||
|
/** |
||||
|
* 执行时长,单位:毫秒 |
||||
|
*/ |
||||
|
@NotNull(message = "执行时长不能为空") |
||||
|
private Integer duration; |
||||
|
/** |
||||
|
* 结果码 |
||||
|
*/ |
||||
|
@NotNull(message = "错误码不能为空") |
||||
|
private Integer resultCode; |
||||
|
/** |
||||
|
* 结果提示 |
||||
|
*/ |
||||
|
private String resultMsg; |
||||
|
|
||||
|
@Override |
||||
|
public String getStreamKey() { |
||||
|
return "api.access.log.create"; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,110 @@ |
|||||
|
package com.win.module.infra.mq.message.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessage; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
/** |
||||
|
* 短信发送消息 |
||||
|
* |
||||
|
* @author 闻荫源码 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class ApiErrorLogMessage extends AbstractStreamMessage { |
||||
|
|
||||
|
/** |
||||
|
* 链路编号 |
||||
|
*/ |
||||
|
private String traceId; |
||||
|
/** |
||||
|
* 账号编号 |
||||
|
*/ |
||||
|
private Long userId; |
||||
|
/** |
||||
|
* 应用名 |
||||
|
*/ |
||||
|
@NotNull(message = "应用名不能为空") |
||||
|
private String applicationName; |
||||
|
|
||||
|
/** |
||||
|
* 请求方法名 |
||||
|
*/ |
||||
|
@NotNull(message = "http 请求方法不能为空") |
||||
|
private String requestMethod; |
||||
|
/** |
||||
|
* 访问地址 |
||||
|
*/ |
||||
|
@NotNull(message = "访问地址不能为空") |
||||
|
private String requestUrl; |
||||
|
/** |
||||
|
* 请求参数 |
||||
|
*/ |
||||
|
@NotNull(message = "请求参数不能为空") |
||||
|
private String requestParams; |
||||
|
/** |
||||
|
* 用户 IP |
||||
|
*/ |
||||
|
@NotNull(message = "ip 不能为空") |
||||
|
private String userIp; |
||||
|
/** |
||||
|
* 浏览器 UA |
||||
|
*/ |
||||
|
@NotNull(message = "User-Agent 不能为空") |
||||
|
private String userAgent; |
||||
|
|
||||
|
/** |
||||
|
* 异常时间 |
||||
|
*/ |
||||
|
@NotNull(message = "异常时间不能为空") |
||||
|
private LocalDateTime exceptionTime; |
||||
|
/** |
||||
|
* 异常名 |
||||
|
*/ |
||||
|
@NotNull(message = "异常名不能为空") |
||||
|
private String exceptionName; |
||||
|
/** |
||||
|
* 异常发生的类全名 |
||||
|
*/ |
||||
|
@NotNull(message = "异常发生的类全名不能为空") |
||||
|
private String exceptionClassName; |
||||
|
/** |
||||
|
* 异常发生的类文件 |
||||
|
*/ |
||||
|
@NotNull(message = "异常发生的类文件不能为空") |
||||
|
private String exceptionFileName; |
||||
|
/** |
||||
|
* 异常发生的方法名 |
||||
|
*/ |
||||
|
@NotNull(message = "异常发生的方法名不能为空") |
||||
|
private String exceptionMethodName; |
||||
|
/** |
||||
|
* 异常发生的方法所在行 |
||||
|
*/ |
||||
|
@NotNull(message = "异常发生的方法所在行不能为空") |
||||
|
private Integer exceptionLineNumber; |
||||
|
/** |
||||
|
* 异常的栈轨迹异常的栈轨迹 |
||||
|
*/ |
||||
|
@NotNull(message = "异常的栈轨迹不能为空") |
||||
|
private String exceptionStackTrace; |
||||
|
/** |
||||
|
* 异常导致的根消息 |
||||
|
*/ |
||||
|
@NotNull(message = "异常导致的根消息不能为空") |
||||
|
private String exceptionRootCauseMessage; |
||||
|
/** |
||||
|
* 异常导致的消息 |
||||
|
*/ |
||||
|
@NotNull(message = "异常导致的消息不能为空") |
||||
|
private String exceptionMessage; |
||||
|
|
||||
|
@Override |
||||
|
public String getStreamKey() { |
||||
|
return "api.error.log.create"; |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,4 +0,0 @@ |
|||||
/** |
|
||||
* 消息队列的消息 |
|
||||
*/ |
|
||||
package com.win.module.infra.mq.message; |
|
@ -0,0 +1,35 @@ |
|||||
|
package com.win.module.infra.mq.message.trends; |
||||
|
|
||||
|
import com.win.framework.mq.core.stream.AbstractStreamMessage; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
|
||||
|
/** |
||||
|
* 短信发送消息 |
||||
|
* |
||||
|
* @author 闻荫源码 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class TrendsMessage extends AbstractStreamMessage { |
||||
|
|
||||
|
@NotNull(message = "表名不能为空") |
||||
|
private String tableName; |
||||
|
|
||||
|
@NotNull(message = "表数据id不能为空") |
||||
|
private Long tableId; |
||||
|
|
||||
|
@NotNull(message = "类型不能为空") |
||||
|
private Integer type; |
||||
|
|
||||
|
@NotNull(message = "内容不能为空") |
||||
|
private String content; |
||||
|
|
||||
|
@Override |
||||
|
public String getStreamKey() { |
||||
|
return "trends.create"; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.win.module.infra.mq.producer.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.RedisMQTemplate; |
||||
|
import com.win.module.infra.mq.message.logger.ApiAccessLogMessage; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class ApiAccessLogProducer { |
||||
|
|
||||
|
@Resource |
||||
|
private RedisMQTemplate redisMQTemplate; |
||||
|
|
||||
|
/** |
||||
|
* 创建访问记录 |
||||
|
* |
||||
|
* @param apiAccessLogMessage |
||||
|
*/ |
||||
|
public void sendMessage(ApiAccessLogMessage apiAccessLogMessage) { |
||||
|
redisMQTemplate.send(apiAccessLogMessage); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package com.win.module.infra.mq.producer.logger; |
||||
|
|
||||
|
import com.win.framework.mq.core.RedisMQTemplate; |
||||
|
import com.win.module.infra.mq.message.logger.ApiErrorLogMessage; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class ApiErrorLogProducer { |
||||
|
|
||||
|
@Resource |
||||
|
private RedisMQTemplate redisMQTemplate; |
||||
|
|
||||
|
/** |
||||
|
* 创建访问记录 |
||||
|
* |
||||
|
* @param apiErrorLogMessage |
||||
|
*/ |
||||
|
public void sendMessage(ApiErrorLogMessage apiErrorLogMessage) { |
||||
|
redisMQTemplate.send(apiErrorLogMessage); |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,4 +0,0 @@ |
|||||
/** |
|
||||
* 消息队列的生产者 |
|
||||
*/ |
|
||||
package com.win.module.infra.mq.producer; |
|
@ -0,0 +1,26 @@ |
|||||
|
package com.win.module.infra.mq.producer.trends; |
||||
|
|
||||
|
import com.win.framework.mq.core.RedisMQTemplate; |
||||
|
import com.win.module.infra.mq.message.trends.TrendsMessage; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Component |
||||
|
public class TrendsProducer { |
||||
|
|
||||
|
@Resource |
||||
|
private RedisMQTemplate redisMQTemplate; |
||||
|
|
||||
|
/** |
||||
|
* 创建访问记录 |
||||
|
* |
||||
|
* @param trendsMessage |
||||
|
*/ |
||||
|
public void sendMessage(TrendsMessage trendsMessage) { |
||||
|
redisMQTemplate.send(trendsMessage); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue