帆的博客

扬帆起航

如何阅读一个开源框架的源码

如果要阅读一个开源框架的源码,我们应该从什么地方入手。首先应该想到的是,从框架启动的入口入手,比如Eureka,肯定是从Eureka服务本身启动的入口开始。或者我们也可以从框架的单元测试开始看,因为单元测试都包含了框架的核心流程和功能。所以我们通过这2个入口,可以通过打断点执行的方式阅读代码的逻辑。下面我将开始学习Eureka的源码,我将基于https://github.com/Netflix/eureka.git 的v1.7.2分支进行阅读,因为我目前所用的SpringCloud引入的就是这个版本。

阅读全文 »

SpringBoot日志处理

默认情况下,SpringBoot会引入spring-boot-starter-logging,也就是logback的日志实现。

在resources下新建logback-spring.xml可以自定义日志配置,这是约定的文件名字。

在spring-boot-starter-logging-2.1.4.RELEASE这个依赖中,在/org/springframework/boot/logging/logback/base.xml位置可以找到SpringBoot提供的一个默认配置,基于这个配置进行自定义

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="com.test.springlecture" level="DEBUG"/>
<springProfile name="default">
<logger name="com.test.springlecture" level="INFO"/>
</springProfile>
</Configuration>
阅读全文 »

SpringApplication

Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:

  • Create an appropriate ApplicationContext instance (depending on your classpath)
  • Register a CommandLinePropertySource to expose command line arguments as Spring properties
  • Refresh the application context, loading all singleton beans
  • Trigger any CommandLineRunner beans
阅读全文 »

微服务学习笔记

什么是微服务

https://martinfowler.com/articles/microservices.html

“Microservices” - yet another new term on the crowded streets of software architecture. Although our natural inclination is to pass such things by with a contemptuous glance, this bit of terminology describes a style of software systems that we are finding more and more appealing. We’ve seen many projects use this style in the last few years, and results so far have been positive, so much so that for many of our colleagues this is becoming the default style for building enterprise applications. Sadly, however, there’s not much information that outlines what the microservice style is and how to do it.

阅读全文 »

基于用户和ip的灰度发布方案

为了能够更好的解决系统新版本上线无法验证的风险,我们通常需要在升级的时候进行灰度发布,下面调研了一个上线灰度发布的流程。

下面先看一张图,然后再用一段文字描述整个发布的逻辑。

阅读全文 »

背景

最近在搭建一个Spring Cloud的项目,在搭建途中,遇到了一些问题,这里记录一下。
在搭建AuthorizationServer的时候,就遇到了问题,我的授权模式是用的password模式,然后是集成了JWT生成access_token。

基本上我是参照这个项目搭建的,https://gitee.com/log4j/pig 。不过因为只是参考,所以我还做了一些改动,而且我们Spring Cloud的版本也不一样,我是F版的。

阅读全文 »

背景

今天同事说在Hystrix的执行方法里打印日志的时候,Sleuth的traceId丢失了,产生了新的traceId,我第一反应是难道是因为Hystrix采用的是线程隔离模式,所以导致sleuth在线程切换的时候丢失了traceId吗?但是我记得Sleuth是针对是Hystrix处理过的,具体的处理的类就是SleuthHystrixConcurrencyStrategy。Spring Cloud Sleuth专门对Hystrix处理过线程切换上下文传递的问题。

阅读全文 »

Zuul 修改URI

背景

最近项目中有一个需求,因为系统要进行重构,所以在重构期间网关需要判断URL请求的是老系统还是新系统。如果请求的是老系统那么就需要根据URL和参数在网关层对进行转换,也就是要修改成新系统的URL,并转发到新系统上去。如果请求的是新系统,那么则不做处理,进行相应的鉴权操作。

阅读全文 »
0%