当前位置:网站首页>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
边栏推荐
- Free chat robot API
- Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
- 2022-02-13 work record -- PHP parsing rich text
- curlpost-php
- Leetcode 450 deleting nodes in a binary search tree
- CTF daily question day44 rot
- 云导DNS和知识科普以及课堂笔记
- How to solve the problems caused by the import process of ecology9.0
- MySQL storage engine
- MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
猜你喜欢
Room cannot create an SQLite connection to verify the queries
Atcoder beginer contest 254 [VP record]
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
Set data real-time update during MDK debug
MDK debug时设置数据实时更新
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
建立时间和保持时间的模型分析
如何制作自己的机器人
Idea远程提交spark任务到yarn集群
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
随机推荐
Uniapp development, packaged as H5 and deployed to the server
Leetcode 450 deleting nodes in a binary search tree
Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
[simple implementation of file IO]
2022-02-13 work record -- PHP parsing rich text
OS i/o devices and device controllers
如何制作自己的機器人
Opencv classic 100 questions
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
Calculate sha256 value of data or file based on crypto++
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
XML配置文件
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Free chat robot API