侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

OCP开源项目:日志公共组件的实现(log-spring-boot-starter)

2022-06-09 星期四 / 0 评论 / 0 点赞 / 87 阅读 / 10849 字

前言企业微服务开放平台 ,历经多家公司生产考验基于layui前后端分离的企业级微服务架构兼容spring cloud netflix & spring cloud alibaba优化Spri

前言

企业微服务开放平台 ,历经多家公司生产考验

  • 基于layui前后端分离的企业级微服务架构
  • 兼容spring cloud netflix & spring cloud alibaba
  • 优化Spring Security内部实现,实现API调用的统一出口和权限认证授权中心
  • 提供完善的企业微服务流量监控,日志监控能力
  • 提供完善的压力测试方案
  • 提供完善的微服务部署方案

项目演示地址

http://59.110.164.254:8066/login.html 用户名/密码:admin/admin

项目监控地址

http://47.98.236.203:3000 用户名/密码:admin/1q2w3e4r

入群学习:(备注:Coder编程)群1:483725710(满2000)群2:897924507

本章主要是将ocp原来的log-core做一个代码优化,采用spring boot enable的方式重构代码。

log-spring-boot-starter

  • pom依赖

  • LogServiceImpl 切换数据源,记录log表

  • LogServiceImpl 切换数据源,记录log表

  • AOP标准日志格式

  • springboot项目中是否使用过EnableCaching

下面咱们按照springboot的方式 编写EnableLogging

  • @Import(LogImportSelector.class)

  • LogImportSelector

  • 使用EnableLogging

总结1.@Import用来导入一个或多个类(会被spring容器托管),或者配置类(配置类里面的bean都会被spring容器托管)2. ImportSelector 该接口的方法的返回值都会被纳入到spring容器管理中

@Import

  • import可以采用importselecor的返回值加入到spring容器
  • import还可以自定义ImportBeanDefinitionRegistrar接口,通过BeanDefinitionRegistry纳入到spring容器

链路跟踪

spring-cloud-sleuth-core

网关传递traceid

方法拦截器设置traceid

aop处理traceid

traceid处理

feign处理traceid

RestTemplate处理traceid

api-gateway

auth-server

grep -rn

HP@owen /cygdrive/d/open-capacity-platform$ grep -rn a26003208271fd94 *logs/auth-gateway/auth-gateway-info.log:740:[auth-gateway:130.75.131.208:9200] [a26003208271fd94] [a26003208271fd94] 2019-09-06 09:38:33.898 INFO 6364 [XNIO-2 task-3] com.open.capacity.client.filter.ResponseFilter request url = http://127.0.0.1:9200/api-auth/validata/code/1263967C-FED7-4732-86D7-8CC6BDF752F5, traceId = a26003208271fd94logs/auth-gateway/auth-gateway-info.log:741:[auth-gateway:130.75.131.208:9200] [a26003208271fd94] [a26003208271fd94] 2019-09-06 09:38:36.703 INFO 6364 [XNIO-2 task-3] com.open.capacity.client.filter.ResponseFilter response url http://127.0.0.1:9200/api-auth/validata/code/1263967C-FED7-4732-86D7-8CC6BDF752F5, traceId = a26003208271fd94oauth-center/logs/auth-server/auth-server-info.log:722:[auth-server:130.75.131.208:8000] [a26003208271fd94] [b26ed6e6877dd47a] 2019-09-06 09:38:34.795 INFO 15168 [http-nio-8000-exec-1] com.open.capacity.log.aop.LogAnnotationAOP 开始请求,transid=a26003208271fd94,  url=com.open.capacity.uaa.server.controller.ValidateCodeController/createCode , httpMethod=null, reqData=["1263967C-FED7-4732-86D7-8CC6BDF752F5"]oauth-center/logs/auth-server/auth-server-info.log:723:[auth-server:130.75.131.208:8000] [a26003208271fd94] [b26ed6e6877dd47a] 2019-09-06 09:38:36.671 INFO 15168 [http-nio-8000-exec-1] com.open.capacity.log.aop.LogAnnotationAOP 请求完成, transid=a26003208271fd94, 耗时=1898, resp=null:

CompletableFuture.runAsync 与链路跟踪

[test-log-center:130.75.131.208:8080] [,d1d8bf482db0af10] 2019-09-16 13:40:25.181 INFO 18088 [http-nio-8080-exec-10] com.open.capacity.log.test.controller.TestController ok[test-log-center:130.75.131.208:8080] [,d1d8bf482db0af10] 2019-09-16 13:40:25.220 INFO 18088 [pool-1-thread-1] com.open.capacity.log.test.controller.TestController oook
  • 异步传递MDC

  • CompletableFuture 绑定自定义TaskExecutor

X-B3-TraceId生产的源头

CompletableFuture.runAsync 与事物问题

需要下沉到另外一个类

文末

.

欢迎关注个人微信公众号:Coder编程欢迎关注Coder编程公众号,主要分享数据结构与算法、Java相关知识体系、框架知识及原理、Spring全家桶、微服务项目实战、DevOps实践之路、每日一篇互联网大厂面试或笔试题以及PMP项目管理知识等。更多精彩内容正在路上~也分享一些杂文~

. .

文章收录至Github: github.com/CoderMerlin…Gitee: gitee.com/573059382/c…欢迎关注并star~

..

.

广告 广告

评论区