mirror of https://github.com/ZhongFuCheng3y/austin
parent
5f12b96c19
commit
6083116471
@ -0,0 +1,36 @@
|
||||
package com.java3y.austin.common.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: sky
|
||||
* @Date: 2023/7/13 10:43
|
||||
* @Description: SimpleTaskInfo
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SimpleTaskInfo {
|
||||
|
||||
/**
|
||||
* 业务消息发送Id, 用于链路追踪, 若不存在, 则使用 messageId
|
||||
*/
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 消息唯一Id(数据追踪使用)
|
||||
* 生成逻辑参考 TaskInfoUtils
|
||||
*/
|
||||
private String messageId;
|
||||
|
||||
/**
|
||||
* 业务Id(数据追踪使用)
|
||||
* 生成逻辑参考 TaskInfoUtils
|
||||
*/
|
||||
private Long businessId;
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.java3y.austin.service.api.impl.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.java3y.austin.common.constant.AustinConstant;
|
||||
import com.java3y.austin.common.domain.SimpleAnchorInfo;
|
||||
import com.java3y.austin.common.enums.RespStatusEnum;
|
||||
import com.java3y.austin.service.api.domain.SendResponse;
|
||||
import com.java3y.austin.service.api.domain.TraceResponse;
|
||||
import com.java3y.austin.service.api.service.TraceService;
|
||||
import com.java3y.austin.support.utils.RedisUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: sky
|
||||
* @Date: 2023/7/13 13:45
|
||||
* @Description: TraceServiceImpl
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class TraceServiceImpl implements TraceService {
|
||||
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Override
|
||||
public TraceResponse traceByMessageId(String messageId) {
|
||||
if (StrUtil.isBlank(messageId)) {
|
||||
return new TraceResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg(), null);
|
||||
}
|
||||
String redisMessageKey = StrUtil.join(StrUtil.COLON, AustinConstant.CACHE_KEY_PREFIX, AustinConstant.MESSAGE_ID, messageId);
|
||||
List<String> messageList = redisUtils.lRange(redisMessageKey, 0, -1);
|
||||
if (CollUtil.isEmpty(messageList)) {
|
||||
return new TraceResponse(RespStatusEnum.FAIL.getCode(), RespStatusEnum.FAIL.getMsg(), null);
|
||||
}
|
||||
|
||||
// 0. 按时间排序
|
||||
List<SimpleAnchorInfo> sortAnchorList = messageList.stream().map(s -> JSON.parseObject(s, SimpleAnchorInfo.class)).sorted((o1, o2) -> Math.toIntExact(o1.getTimestamp() - o2.getTimestamp())).collect(Collectors.toList());
|
||||
|
||||
return new TraceResponse(RespStatusEnum.SUCCESS.getCode(), RespStatusEnum.SUCCESS.getMsg(), sortAnchorList);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.java3y.austin.service.api.domain;
|
||||
|
||||
import com.java3y.austin.common.domain.SimpleAnchorInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: sky
|
||||
* @Date: 2023/7/13 13:38
|
||||
* @Description: TraceResponse
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TraceResponse {
|
||||
/**
|
||||
* 响应状态
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 响应编码
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 埋点信息
|
||||
*/
|
||||
private List<SimpleAnchorInfo> data;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.java3y.austin.service.api.service;
|
||||
|
||||
import com.java3y.austin.service.api.domain.TraceResponse;
|
||||
|
||||
/**
|
||||
* 链路查询接口
|
||||
* @Author: sky
|
||||
* @Date: 2023/7/13 13:35
|
||||
* @Description: TraceService
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public interface TraceService {
|
||||
|
||||
/**
|
||||
* 基于消息 ID 查询 链路结果
|
||||
* @param messageId
|
||||
* @return
|
||||
*/
|
||||
TraceResponse traceByMessageId(String messageId);
|
||||
}
|
Loading…
Reference in new issue