One-click upgrade of Spring Boot monolithic application to Spring Cloud Alibaba

Author: ten sleep

background

With the popularity of service frameworks such as Apache Dubbo, Nacos, and Spring Cloud, more and more enterprises have begun to adopt the microservice architecture to build their applications. Microservices architecture enables businesses to split their applications into multiple small services that can be deployed and scaled independently. This architectural pattern also makes it easier for enterprises to implement agile development and continuous delivery, thereby improving their business efficiency and responsiveness.

image

Four major parts of microservices: registration center, service provider, service consumer, service governance

Nowadays, with the emergence and maturity of several major microservices such as service providers, service consumers, service registration centers, and service governance, we use microservice development to not only achieve rapid development, but also pursue the efficiency of microservices. and stable.

image.png

Monolith or microservice?

From the above figure, we can see that with the increase of business scale, there is an intersection between the selection trend of monolithic architecture and microservice architecture. After the intersection point, choose the microservice architecture. The larger the business scale, the more you can enjoy the efficiency improvement brought by the microservice architecture. We can observe that this intersection is continuously moving to the left. The rapid development of the digitalization process generally makes the IT systems of enterprises more complex. The technology standardization promoted by open source and cloud computing is greatly reducing the technical threshold of microservice architecture. Small companies can also play well with microservices on the cloud. With the advent of this trend, enterprises that are still using a monolithic architecture are gradually considering the transformation to microservices. We found that most Java applications on the cloud are still based on SpringBoot. Due to the simplicity of the Spring Boot application architecture, the client can implement service calls only through http and domain name. Therefore, many small and medium-sized companies still use this method for application development. From a technical point of view, how do we upgrade the SpringBoot application to the microservice architecture and enjoy the technical dividends brought by microservice governance? We need to increase SpringCloud's maven dependency? Need business code transformation? This article can answer you without a single line of code change.

This solution can realize the registration, discovery and management capabilities of Java applications without intrusion through MSE.

  1. The current registration center product capabilities provided by MSE are mainly focused on non-persistent service discovery, that is, the state of the service is maintained on the client, which requires the business side to rely on the SDK to actively register the service and maintain the heartbeat; this solution provides a persistent service discovery capability .
  2. Solve the problem of cross-platform service discovery, such as cross-K8s service discovery, mutual discovery of non-K8s services and K8s services, etc.
  3. Non-intrusive implementation of service governance capabilities based on Spring Boot applications, such as full link grayscale, current limiting and degradation, security and trustworthiness, etc.

Program Practice and Exploration

In order to verify this scenario, we provide a slightly more complex Demo, through which we demonstrate how to realize the service registration and service management of Spring Boot applications without intrusion through MSE. Demo is based on K8s Service for service discovery and request calls through a simple HttpClient. The detailed request is as follows:

➜  ~ curl http://47.97.117.48/A/spring_boot                                   
A[10.0.3.238] -> B[10.0.3.227] -> C[10.0.3.230]%

The schema looks like this:

image

After introducing the Demo, let's demonstrate step by step how to register services through service governance.

Complete service registration through service governance

  1. Go to the corresponding MSE Nacos instance page, select create service

image.png

  1. After we fill in the service name and group name, we can choose a service governance application to register

  2. After enabling the health check capability, we can also choose the health check protocol

image.png

  1. After clicking OK, we have realized the registration of applications and instances to MSE Nacos through service governance

image

  1. According to the configuration in the figure below, we register application A as sc-A, application B as sc-b, and application C as sc-c

image

  1. At the same time, we modify the Nacos address configuration of the Zuul application to register it in MSE Nacos through the SDK

  2. For the services we register through service governance, we can also take the corresponding node offline from MSE Nacos through service governance

image

image.png

  1. Click the service offline on the node details page in MSE service management, and realize the service offline from the registration center without restarting the application pod

image.png

So far, we have completed service registration through service governance.

Complete service subscription through service governance

  1. We add the following Env to the application that needs to subscribe to the Nacos service

image.png

  1. How to subscribe to the corresponding service?

Our Http request domain name can directly call the corresponding service, for example:

restTemplate.getForObject("http://sc-b:20002/spring_boot", String.class);

Among them, sc-b is the service name. The default group name can be specified by mse_nacos_group. If you need to specify the group name, you can call http://sc-b:20002/spring_boot?mse_nacos_group=xxx .

  1. verify

a. It can be verified through the MSE Nacos console to clarify the subscription relationship

image.png

b. Through end-to-end request verification

➜  ~ curl http://47.97.117.48/A/spring_bootA[10.0.3.238] -> B[10.0.3.229] -> C[10.0.3.241]%

Non-intrusive implementation of full link gray scale based on SpringBoot application

image

So far, we have the full-link grayscale capability that meets the above scenarios by default.

➜  ~ curl http://47.97.117.48/A/spring_boot -H "x-mse-tag: gray"              
Agray[10.0.3.240] -> B[10.0.3.229] -> Cgray[10.0.3.241]%

Summarize

Using the Spring Boot application, you can quickly enjoy the release experience brought by the full link grayscale capability. Through the integration of the MSE service governance capability and the Nacos engine, we can further simplify and reduce the part that R&D needs to pay attention to on the cloud, and the client of the application can be lightweight, further improving the R&D efficiency.

image

Click here to enter the microservice engine MSE official website to view

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/3874284/blog/8725618
Recommended