Spent a few days to transform the project from Spring Boot monolithic project into Spring Cloud microservices. To be honest, the current volume of business is far from microservices, standalone can completely hold. But can not help the leadership above the daily urging, forget it, let’s do it.

The hardest part is not the technology

The most time consuming part of switching from standalone to microservices is not in the technology upgrade. Instead, it’s the business segmentation, where the previous strong relationships need to be reorganized, separated and aggregated. Believe me, when you go to split standalone applications the most headache must be this. There are two platforms business is too complex directly first not to split, first integrated into. Everything in the spirit of the most simplified development ideas, because the above did not give much time to toss this, engage in development is really humble.

Technical transformation process

In the original standalone project, we had a project like spring-boot-dependencies to manage the dependencies and all the libraries and dependency versions of the project were managed by this project. If you want to integrate a set of Spring Cloud components, you just need to add the Spring Cloud dependency management project to it.

1
2
3
4
5
6
7
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>2020.0.3</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

If you need to integrate Spring Cloud Alibaba, you need to add additional dependency management items.

Nacos vs Consul

Nacos is one of the core projects in Spring Cloud Alibaba, acting as a registry and configuration center in the microservices architecture, with many online tutorials and now very many users and very powerful features. But I had some problems with the cluster and didn’t solve them (my own level problem), so I’m going to use Consul directly (Eureka is not considered, because it is no longer maintained).

As for why use Consul, first of all, not used, curiosity is heavy; the second point Consul as the field of well-known products, in many large enterprises have landing practice, as if microblogging used this. Features are weaker than Nacos, configuration management, service registration and discovery, management UI is not less. Since Spring Cloud abstracts the configuration of both, there are no obstacles to switch except replacing dependencies and changing the configuration.

HashiCorp

Here is an additional science, it is surprising that the surrounding are not aware of HashiCorp Inc. It is a unicorn in the open source world, valued at more than $5 billion, and the quality of their open source products is very high, with its star products including Consul, Nomad, Vault, Vagrant, Packer, Terraform and so on. Their CEO founder just quit and went back to development because he likes writing code too much.

Here is an additional science, it is surprising that the surrounding are not aware of HashiCorp Inc. It is a unicorn in the open source world, valued at more than $5 billion, and the quality of their open source products is very high, with its star products including Consul, Nomad, Vault, Vagrant, Packer, Terraform and so on. Their CEO founder just quit and went back to development because he likes writing code too much.

OpenFeign

For remote call frameworks, there are not too many technology stacks available.

If you want to understand Feign thoroughly, you must seriously learn the OpenFeign invocation process. If you have the ability, it is best to look at the source code. There are many tutorials on the Internet, but the content of the “token relay” network is very little and not clear, but I took some time to get it done.

Load Balancing

Robbin as a load balancing component is not maintained open source anymore. The good thing is that Spring has officially implemented a new load balancing component itself

1
2
3
4
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>

Fault Tolerance

Hystrix is also obsolete, currently only Ali’s Sentinel and Resilience4J can choose, since I abandoned Nacos, then use Resilience4J, fuse, limit flow, retry are available, but not as many features as Sentinel, you can choose according to your needs. In addition, Resilience4J uses a lot of functional programming, and those who want to refine functional programming must learn its source code.

Security

About the security transformation, or based on Spring Security to do, but is to separate the authentication and authorization forensics to achieve. Other services are OAuth2.0 resource server, only need to verify the JWT can be, currently does not have complete access to OAuth2.0 protocol, because the need for a transition period, the architecture is not a quick fix.

Gateway

First of all Spring Cloud Gateway is easy to use, but there is no UI and route persistence needs to be implemented by yourself. In short it is not very easy to use, but the good thing is that it is not difficult to use. If you don’t have time, take it and make do with it. If I have time, I have to try Apache Apisix or Orange which are based on Openresty and are much more powerful than Spring Cloud Gateway in terms of performance and features.

Logs

Logging I think most people use EFK system, I chose Loki here, Sidebar mode is very easy to integrate. If there is a need to use EFK again later.

Currently Jaeger, Zipkin, Skywalking are good, more inclined to Skywalking, have not yet studied.

Distributed transactions

Not at the moment! Wait until something goes wrong. Distributed transactions need to be seen in the context of the business, and if the business division is more reasonable, distributed transactions are not a must.

To summarize

In fact, Spring Boot monolithic projects transformed into Spring Cloud microservices system is very smooth overall. The largest amount of work is the business division, not the choice of technology system and integration, my idea is to put together the strong correlation first, the common independent services. Component integration does not take much time. In addition, there should be a transition period, first transform the edge of the business to test the water, stability overrides everything.

Reference https://felord.cn/2springcloud.html