Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi

2024/04/1913:15:35 technology 2000

Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud middleware

Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

Introduction

Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework of Tencent open source, Spring Cloud Tencent implements Spring Cloud Standard microservice SPI, developers can quickly develop Spring Cloud microservice architecture applications based on Spring Cloud Tencent. The core of Spring Cloud Tencent relies on Tencent's open source one-stop service discovery and governance platform Polarismesh to implement various distributed microservice scenarios.

Github Address:

https://github.com/Tencent/spring-cloud-tencent

Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

About the author

Zhang Le

Tencent Cloud technical expert, Spring Cloud Tencent community leader, core R&D of Tencent Cloud microservice engine TSE. He has been committed to the research and development of microservices and fields, such as configuration center, registration center, service governance and other fields.

Zhang Haotian

Tencent senior R&D engineer, Spring Cloud Tencent PMC, Polaris Java PMC.

Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

Why do Spring Cloud Tencent

Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews. Spring Boot + Spring Cloud is still the most mainstream framework in the Java ecosystem

In April 2014, Spring Boot released version 1.0. After 8 years of development, Spring Boot has become the de facto standard for Java development frameworks. In the field of distributed microservices, Spring Cloud released the Angel.SR5 version in January 2016. Spring Cloud inherits Spring Boot's core ideas of componentization, low configuration and rapid integration, and also defines a set of standard microservice SPI.

Based on this SPI, excellent microservice solution implementation suites such as Spring Cloud Netfix have emerged. In terms of remote service invocation frameworks, Feign and RestTemplate are based on the universal HTTP protocol and have natural advantages in ease of use, observability, and cross-language. So Spring Cloud has thrived since the first version was released in 2016.

Judging from the industry situation, Spring Boot + Spring Cloud is currently one of the most widely used development frameworks in Java.

ServiceMesh, represented by Istio, began to be incubated in the community in 2018. By 2022, there are now many ServiceMesh products. The core idea of ​​ServiceMesh is to sink the basic capabilities related to service invocation to an independent sidecar process, and manage traffic through a traffic proxy. No solution is a panacea, and the Sidecar model also has some problems. For example: It is highly dependent on the Paas capabilities of the underlying personnel to manage Sidecar (injection, version management, upgrade, etc.). Sidecar needs to occupy certain additional resources, increase certain network delays, and increase the difficulty of troubleshooting, etc. Therefore, there are not many domestic companies that can actually implement ServiceMesh.

In summary, we believe that Spring Boot + Spring Cloud will still be the mainstream microservice solution for Java for a long time to come, although it does not seem as advanced as Istio and Dapr. On the premise of meeting the business development demands of enterprises, a low-cost, efficient, and stable architecture solution is the best solution.

    . Tencent’s open source PolarisMesh in 2021 provides a one-stop microservice solution

    Polaris is a one-stop microservice solution that integrates a registration center, configuration center, and service governance center. It has covered 90 % of the business, the number of registered instance nodes has reached 5 million. After 21 years of open source, there are also external companies in the community that have implemented production.

    Architects within the company often make some technology selections, such as Zookeeper, Consul, Nacos, etc. for the registration center, Apollo and Nacos for the configuration center, and Sentinel for current limiting and fusing. Multiple components also mean that multiple sets of services need to be maintained, which takes up more resources and makes it difficult to achieve consistency in user experience.

    Therefore, the one-stop microservice solution can greatly simplify technology selection, operation and maintenance, and resource costs. Of course, Polaris can also be used as part of the solution. For example, only Polaris' services are used for registration and discovery, and the configuration center still selects Apollo. After all, it is still the same truth. There is no one-size-fits-all solution. The best solution is the solution that suits the needs of the enterprise's business.

    In addition, Polaris also has certain advantages in horizontal comparison of certain capabilities. For example, the completely stateless registration center is more convenient for operation and maintenance, and the powerful service routing capability supports complex business scenarios. Specific product functions will be introduced in more detail in the second part.

  • . Summary

    Based on the above two core reasons, it is logical to use Polaris as an out-of-the-box implementation suite for Spring Cloud. It can satisfy both Spring Cloud users and Polaris Java users. Of course, Spring Cloud Tencent currently only supports the capabilities of Polaris, and will support more outstanding open source products from Tencent in the future.

    Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

    Why Spring Cloud Tencent

    Currently, Spring Cloud Tencent mainly provides common service registration and discovery, configuration center, service routing, current limiting and fusing, and metadata link transparent transmission capabilities in the microservice field. The capabilities of each part will be introduced in detail next.

    Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

    (Picture: Spring Cloud Tencent capability map)

      .1 Service registration and discovery (Spring Cloud Tencent Polaris Discovery)

      Service registration and discovery is one of the core functions of Spring Cloud Tencent. By implementing Spring Cloud's service registration and discovery The standard interface provides microservice applications with the ability to quickly access the Polaris Service Registration Center. Developers can use Polaris' service registration and discovery functions by simply introducing Spring Cloud Tencent service registration and discovery dependencies. After access service registration and discovery, you can also use the powerful service governance capabilities provided by Polaris on demand, such as scenario-based service routing capabilities, service circuit breaker capabilities, etc. It is convenient for developers to make personalized service governance configurations based on the actual production scenarios of microservices.

      Polaris' service model includes namespaces, services and service instances. The

      namespace

      namespace provides a mechanism for logical isolation of resources under the same registration center. Service names under the same namespace must be unique, but services with the same name are allowed to exist across namespaces. Namespaces are often used to distinguish different environments or service isolation between multiple businesses.

      service

      service is also a logical concept, providing service capabilities in a specific business field. For example, order services, user services, transfer services, etc.

      Service instance

      Service instance is a specific physical node under the service

      Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

      (Figure: Service instance details)

      Spring Cloud Tencent provides some expansion capabilities in terms of basic service registration discovery. First of all, Spring Cloud Tencent integrates some routing plug-ins of Polaris. By changing the isolation status or weight value of the service instance on the Polaris console page, the dynamic online and offline features of the service instance can be realized, as shown in the figure above.

      Spring Cloud Tencent also provides advanced functions of multi-service registration and discovery.For example, multiple departments or organizations within the company use different service registration centers. When the decision-making technology stack is unified or migrated to the Polaris registration center, business transformation needs to be carried out in a smooth manner rather than directly replacing the original SDK. Access the Polaris Registration Center. At this time, you can use Spring Cloud Tencent's multi-service registration and discovery capabilities to help developers' microservice applications transition through the awkward period of technology stack conversion.

      Spring Cloud Tencent provides such a series of peripheral functions for service registration and discovery, which improves the governance and control capabilities of the microservice architecture.

        .2 Configuration Center (Spring Cloud Tencent Polaris Config)

        In the first half of this year, Polaris began to support the capability of the configuration center. The core configuration triplet model of Polaris Configuration Center is:

        • Namespace

        is used for the ability of logically isolated clusters, such as commonly used in isolated environments.

        • FileGroup

        configuration file group, a collection of configuration files. In Spring Cloud Tencent, our recommended best practice is to use an application as a FileGroup. For framework class configuration, use the framework name as a FileGroup, for example dubbo.

        • File

        configuration files, such as properties and yml format configuration files. The configuration file is the smallest management unit, not the configuration items in the configuration file.

        [Namespace, FileGroup, File] uniquely locates a configuration file. When designing the model, we referred to the mainstream configuration center products in the industry. We believe that the concepts of configuration files and configuration file groups are widely recognized by developers and have the lowest cost of understanding the configuration domain model , such as a folder on a local disk. and document concept. The core capabilities of the

        configuration center are configuration management capabilities and dynamic real-time push capabilities. In terms of configuration management, an application often has a lot of configuration files. How to manage configuration files clearly is a very important ability. When we designed the UI of the management console, we pioneered the use of / as the delimiter to display file names in a tree format. As shown in the figure below, directories can be divided according to application modules, and the messy configuration files under an application can be clearly managed through directories.

        Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

        (Picture: Configuration file management page)

        In addition, in terms of Spring Cloud integration, it is known that Spring Boot will automatically load application.yml, application.properties and the higher priority application-${activeProfile}.yml file in the application resources directory. . When integrating Spring Cloud Tencent Polaris Config, we completely used this native configuration loading mechanism. That is, when Spring Cloud Tencent Polaris Config starts, it will automatically load the application.yml and application-${activeProfile}.yml files under the application file group into the Spring container. When migrating, users only need to upload all configuration files in the resources directory to Polaris intact.

          .3 Service routing (Spring Cloud Tencent Polaris Router)

          In the field of microservices, due to the fine-grained split deployment of services, services have become very lightweight and flexible. It becomes even more powerful after combining the extremely fast elasticity capabilities of k8s cloud native. However, the underlying Paas capabilities only provide basic elastic capabilities. To truly exert the capabilities, you need to rely on the upper layer's traffic allocation capabilities.

          Looking at the Spring Cloud ecosystem, there are not many component suites that can deeply integrate Spring Cloud to provide scenario-based service routing capabilities. Here is an explanation of the scenario. The ability of the service calling framework to implement service routing according to certain rules is called the underlying atomic capability. Atomic capabilities are very general capabilities, but in many cases they cannot be directly used in specific business scenarios. For example, common test environment grouping, nearest routing, blue-green release, etc. are called scenarios.Only after service routing is scenario-based can it truly serve the business out of the box.

          Spring Cloud Tencent Polaris Router currently implements two scenario-based routing capabilities and a very flexible rule routing capability. The

          metadata routing

          service instance will be attached with a set of metadata, such as environmental information, computer room information, etc. Metadata routing simply means routing based on metadata information. This is still a bit abstract. Let's explain it with an example of test environment .

          Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

          (Picture: Schematic diagram of development environment )

          The above picture is a very classic solution for resolving conflicts in the test environment. In an iteration, SvcA needs to be jointly debugged with SvcD. When the team size is small, the stable environment can be directly deployed into the development branch code and then jointly debugged. However, when multiple development tasks are performed in parallel, contention for the environment will occur. One solution is to independently deploy a full-link environment for each development task. This method is time-consuming, labor-intensive and ineffective. The most mainstream approach in the industry is as shown in the figure above. Each development task sub-environment only needs to deploy joint debugging applications, and services on the link that are not in the sub-environment are routed back to the stable environment.

          uses Spring Cloud Tencent. In order to achieve the above purpose, you only need to add the following two environment variables when deploying each service.

          • SCT_METADATA_CONTENT_ENV=dev1
          • SCT_METADATA_CONTENT_TRANSITIVE=ENV

          Spring Cloud Tencent Polaris Router component will automatically read the above environment variables and give priority to the target instance with the same ENV value as the current instance during each service call.

          metadata routing is used in a wide range of scenarios. Please refer to the Github Wiki for more details.

          rule routing

          metadata routing is essentially filtering based on the metadata of service instances. It is a built-in service routing capability to support specific scenarios. There is no need to issue any routing rules, and it is very simple to use.

          The actual business scenarios are very complex, such as the following typical business scenarios:

          • Internal employees are routed to a production grayscale environment, external ordinary users are routed to a production formal environment
          • VIP customers are routed to a high-security environment, and ordinary customers are routed In the normal environment

          , the above two business scenarios cannot be implemented through metadata routing. Because it involves business request parameters, not system-dimensional environment variables. Rule routing is a set of rule-based service routing implementations used to meet complex business scenarios.

          A typical rule is as shown in the figure below:

          Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

          (Figure: routing rule configuration page)

          The meaning of the above figure is: when the uid parameter value of HTTP Query Param is 100, the instance grouping of ENV=gray is called. Most complex business scenarios can be described through routing rules.

          For ease of use, Spring Cloud Tencent has a built-in set of expression tag rules to automatically parse tag values ​​from HTTP requests. The currently supported expression rules are:

          • ${http.query.xxx}
          • ${http.header.xxx}
          • ${http.cookie.xxx}
          • ${http.method}
          • ${http.uri}

          Rule routing is relatively complex, please refer to the Github Wiki for more details.

          Nearest routing

          Production environment services often require multi-cabinet, multi-computer room, and multi-regional deployment for high availability, disaster recovery and other capabilities.

          Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

          (Figure: Deployment model diagram)

          As shown in the above figure, the range from small to large is: Campus Zone Region All. Campus, Zone, and Region are uniformly defined as metadata in the service registration discovery domain model, which is a special location. Metadata (Location Metadata).

          Nearby routing, as the name suggests, selects target service instances from high to low according to the priority of the same Campus, the same Zone, and the same Region when calling the service. The core is to reduce the network time consumed by service calls due to physical distance. Essentially, proximity routing is metadata routing based on a specific set of location metadata.

          uses Spring Cloud Tencent to implement nearby routing. You only need to add the following environment variables to the service instance.

          • SCT_METADATA_CAMPUS
          • SCT_METADATA_ZONE
          • SCT_METADATA_REGION

            .4 Service rate limit (Spring Cloud Tencent Polaris Ratelimit)

            As the business grows, the network The number of requests is also increasing, resulting in explosive traffic surges on the server side of business applications in some scenarios. Therefore, some protection measures need to be given to service providers. Through the service current limiting function, developers can control QPS to avoid being overwhelmed by instantaneous traffic peaks, thereby ensuring high system availability. There are two main application scenarios for service current limiting, overload protection and business anti-brushing. Overload protection is to protect the business from being overwhelmed by sudden traffic, and business anti-brushing is to prevent malicious users from sending too much traffic to affect other normal users. Spring Cloud Tencent has built-in current limiting Filter for Spring Web and Spring WebFlux scenarios to help businesses quickly access Polaris' current limiting capabilities.

            Spring Cloud Tencent supports two types of service current limiting capabilities provided by Polaris, namely stand-alone current limiting and distributed current limiting.

            Single-machine current limit

            Single-machine current limit is the current limit for a single adjusted instance. The traffic limit only takes effect for the current adjusted instance and is not shared, as shown in the figure below. Single-machine current limiting is generally used to protect the service itself from being overwhelmed. The quota is calculated based on the capacity of each service cluster's single machine.

            Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

            (Picture: Example of single-machine current limiting)

            The effect of single-machine current limiting is divided into fast failure and uniform queuing. Fast failure means that when QPS reaches the quota specified by the current limiting rule, it will immediately return a current limiting type error response to all requests that exceed the threshold. Uniform queuing is a peak-shaving and valley-filling current limiting method based on the leaky bucket algorithm, which helps the server ensure a uniform processing state when the traffic peak reaches, so that some requests can still be processed after a period of queuing waiting time. be processed rather than failing outright. For a detailed introduction to uniform queuing, please refer to the official Github Wiki.

            distributed current limiting

            distributed current limiting is the current limiting for all instance levels under the service. Multiple service instances share the same global traffic limit, as shown in the figure below. Distributed current limiting is generally suitable for protecting third-party services or public services (such as protecting databases); or it can be used to limit current at the gateway layer to protect back-end services accessed through the gateway.

            Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

            (Figure: Distributed current limiting example)

            Spring Cloud Tencent provides the ability to customize current limiting rules. Developers can customize corresponding current limiting rules according to their own business scenarios.

            Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

            (Figure: Current limiting rule configuration interface)

              .5 Service circuit breaker (Spring Cloud Tencent Polaris Circuitbreaker)

              In the operation and maintenance scenario of the microservice architecture, sometimes single-point service instance failures will be encountered. If they cannot be eliminated in time, , then there will still be requests forwarded to the failed service instance.Spring Cloud Tencent provides the capability of service circuit breaker. By reporting the results of each call between services, it can determine whether the called service has failed, then shield it, and start a scheduled task to detect the circuit breaker instance. Perform a half-open recovery on it after the recovery conditions are met. After half-open recovery, a small number of requests are released for real business request detection. And judge whether it is fully restored based on the real business detection results. This function can effectively eliminate abnormal service instances and provides important help for service governance.

                .6 Summary

                The above is just a brief introduction to some of the capabilities of Spring Cloud Tencent. If you want to learn more about more capabilities, please visit our Github official homepage.

                Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

                Planning and Vision

                The beginning of the article mentioned why we want to do Spring Cloud Tencent. We firmly believe that Spring Cloud will remain the mainstream solution for microservices in the Java field for a long time. We hope to combine the one-stop microservice capabilities of Polaris to lower the threshold of microservice architecture and provide a full set of out-of-the-box microservice solutions for the majority of enterprises. This allows enterprises to focus more on the development of their own business and improve productivity.

                A useful product needs to be polished in a variety of scenarios for stability, ease of use, and continuous improvement of its own product capabilities. Here are some of the points we currently think of that need support and improvement. Of course, as the product develops and more and more users use it, there will be more demands, and we will continue to iterate.

                Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

                (Picture: SCT Planning)

                Author: Zhang Haotian, Zhang Le, Source: Tencent Cloud Middleware Introduction Recently, Spring Cloud Tencent was officially open sourced on June 14. As a one-stop microservice framework open sourced by Tencent, Spring Cloud Tencent implements the Spring Cloud standard microservi - DayDayNews

                Why do Spring Cloud Tencent

                • If you are also a Spring Cloud enthusiast
                • If your company is using Spring Cloud and there are some good practices
                • If your The company is selecting microservice technology. .. ...

                Please join us. Your suggestion, issue, Pull Request or even just a small Star is our greatest support and the driving force for our continuous iteration.

                Github address: https://github.com/Tencent/spring-cloud-tencent

technology Category Latest News