当前位置:网站首页>Starting from 1.5, build a micro Service Framework - call chain tracking traceid
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
2022-07-06 00:36:00 【InfoQ】
Preface
1
Core functions
- Split multiple micro service modules , Draw out one demo Microservice module for expansion , Completed
- Extract core framework modules , Completed
- Registry Center Eureka, Completed
- The remote invocation OpenFeign, Completed
- journal logback, contain traceId track , Completed
- Swagger API file , Completed
- Configure file sharing , Completed
- Log retrieval ,ELK Stack, Completed
- Customize Starter, undetermined
- Consolidated cache Redis,Redis Sentinel high availability , Completed
- Consolidate databases MySQL,MySQL High availability , Completed
- Integrate MyBatis-Plus, Completed
- Link tracking component , undetermined
- monitor , undetermined
- Tool class , To be developed
- gateway , Technology selection to be determined
- Audit log entry ES, undetermined
- distributed file system , undetermined
- Timing task , undetermined
- wait
One 、 Pain points
It hurts a little : Multiple logs in the process cannot be traced
Pain point two : How to correlate logs across Services
Pain point three : How to correlate logs across threads
It hurts four : The third party calls our service , How to track ?
Two 、 programme
1.1 Solution
1.2 MDC programme
3、 ... and 、 Principle and practice
2.1 Track multiple logs of a request
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %X{traceId} %-5level %logger - %msg%n</pattern>
header
traceId
Sample code
/**
* @author www.passjava.cn, official account : Wukong chat structure
* @date 2022-07-05
*/
@Service
public class LogInterceptor extends HandlerInterceptorAdapter {
private static final String TRACE_ID = "traceId";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String traceId = request.getHeader(TRACE_ID);
if (StringUtils.isEmpty(traceId)) {
MDC.put("traceId", UUID.randomUUID().toString());
} else {
MDC.put(TRACE_ID, traceId);
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// Prevent memory leaks
MDC.remove("traceId");
}
}
/**
* @author www.passjava.cn, official account : Wukong chat structure
* @date 2022-07-05
*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Resource
private LogInterceptor logInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(logInterceptor).addPathPatterns("/**");
}
}
2.2 Track multiple logs across Services
/**
* @author www.passjava.cn, official account : Wukong chat structure
* @date 2022-07-05
*/
@Configuration
public class FeignInterceptor implements RequestInterceptor {
private static final String TRACE_ID = "traceId";
@Override
public void apply(RequestTemplate requestTemplate) {
requestTemplate.header(TRACE_ID, (String) MDC.get(TRACE_ID));
}
}
Four 、 summary
边栏推荐
- Codeforces Round #804 (Div. 2)【比赛记录】
- Ffmpeg learning - core module
- NLP basic task word segmentation third party Library: ICTCLAS [the third party library with the highest accuracy of Chinese word segmentation] [Chinese Academy of Sciences] [charge]
- What is information security? What is included? What is the difference with network security?
- 如何制作自己的机器人
- Spark-SQL UDF函数
- OS i/o devices and device controllers
- Codeforces round 804 (Div. 2) [competition record]
- Problems and solutions of converting date into specified string in date class
- Spark AQE
猜你喜欢
Uniapp development, packaged as H5 and deployed to the server
Intranet Security Learning (V) -- domain horizontal: SPN & RDP & Cobalt strike
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
Atcoder beginer contest 258 [competition record]
Leetcode:20220213 week race (less bugs, top 10% 555)
Spark SQL空值Null,NaN判断和处理
[designmode] composite mode
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
随机推荐
Idea远程提交spark任务到yarn集群
Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
如何制作自己的机器人
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Common API classes and exception systems
AtCoder Beginner Contest 254【VP记录】
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
数据分析思维分析方法和业务知识——分析方法(二)
免费的聊天机器人API
MySQL存储引擎
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Promise
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
Ffmpeg learning - core module
Spark SQL UDF function
Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
MDK debug时设置数据实时更新
Classical concurrency problem: the dining problem of philosophers
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
Key structure of ffmpeg -- AVCodecContext