takeaway

Are you still bothered by code changes? Are you still depressed by the restrictions of the cloud platform? Are you still upset about coupling your business to your cloud services framework? Here comes the Gospel, comrades! The latest version of Tencent micro service platform TSF launched the native application access mode, without a line of code transformation, no need to re-compile, no need to rebuild the program package, native Spring Cloud applications directly on!

The authors introduce

Pei-pei zhang

Senior engineer of Tencent Cloud Micro Service team

TSF Mesh research and development and responsible person

Keen on cloud native and open source technologies, he has rich experience in container, Service Mesh, message queue, block chain and other fields, and is currently committed to the implementation and promotion of Service Mesh technology

background

Spring Cloud provides a one-stop solution for microservice system architecture, and makes use of the development convenience of Spring Boot to subtly simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, message bus, load balancing, circuit breakers, data monitoring, distributed call chain, etc. With a simple programming model provided by Spring Cloud, we can easily build microservice projects based on Spring Boot.

However, this is just a convenience for developers to develop microservices applications. The resulting applications need to run in a production environment. Therefore, we also need to:

  1. Stable operating environment, such as virtual machine environment or container environment, and can carry out life cycle management for micro-service applications.

  2. Spring Cloud is a highly available registry. Although Spring Cloud supports Eureka, Zookeeper or Consul for service registration and discovery, we need to build and ensure its high availability by ourselves.

  3. A unified control plane governs services. Spring Cloud integrates a large number of service governance components, but there is no unified control plane for management, which brings a lot of pressure to large-scale micro-service governance.

  4. Visual data operation services, such as log service, monitoring service and distributed call chain service, such as Spring Cloud realized the distributed call chain by introducing Sleuth and was compatible with Zipkin, HTrace and ELK, but these back-end services need to be built by ourselves and ensured their stability.

In other words, it is only the first step for us developers to develop the application and build the Jar package. To ensure the stable operation and continuous operation of the application, we also need a micro-service platform to meet the above requirements, which is exactly the value of TSF — Tencent Service Framework:

  1. TSF provides one-stop application lifecycle management services. Manage the entire process from application deployment to application running, including creating, deleting, deploying, rolling back, expanding capacity, going offline, starting and stopping applications, and supporting version tracing.

  2. TSF provides efficient service registry discovery capabilities. Provides a high availability guarantee mechanism, such as second-level service registration discovery and local registration information caching, service instance discovery exception alarm, and cross-AZ disaster recovery.

  3. TSF provides fine-grained service governance capabilities. Supports multi-level service governance of services and apis. Fine-grained traffic control in the form of labels is implemented to implement functions such as grayscale advertising, nearby routing, fusing traffic limiting, service fault tolerance, and access authentication.

  4. TSF provides three-dimensional application data operations. Provides tools for monitoring application performance indicators, analyzing distributed call chain, service dependency topology, and log services, helping you efficiently analyze application performance bottlenecks and troubleshoot faults.

Since TSF meets all operating requirements, is it possible for a native Spring Cloud application to access TSF directly and run it?

The original access mode is TSF

TSF supports the native Spring Cloud microservices framework, but for older VERSIONS of TSF (V1.27 or earlier), Spring Cloud applications need to be modified to access.

The old VERSION of TSF supports two access modes: common application and Mesh application.

For common application access, SDK dependency and annotation code need to be modified:

  • The SDK dependencies of TSF corresponding to the Spring Cloud version are introduced in POM.xml

<parent> <groupId>com.tencent.tsf</groupId> <artifactId>spring-cloud-tsf-dependencies</artifactId> <version><! </version> </parent>Copy the code
<dependency> <groupId>com.tencent.tsf</groupId> <artifactId>spring-cloud-tsf-starter</artifactId> <version><! </version> </dependency>Copy the code
  • Add the @enabletsf annotation to the Application class:

/ / omitted unrelated code below import org. Springframework. TSF. The annotation. EnableTsf; @SpringBootApplication @EnableTsf public class ProviderApplication { public static void main(String\[\] args) { SpringApplication.run(ProviderApplication.class, args); }}Copy the code

For the access of Mesh applications, take virtual machine deployment as an example, build a program package in Mesh mode:

1. Add the spec.yaml file

apiVersion: v1
kind: Application
spec:
  services:
    - name: provider
      ports:
        - targetPort: 10881
          protocol: http
      healthCheck:
        path: /health
Copy the code

2. Add the start.sh startup script

! / bin/bash already \ _run = \ ` ps - ef | grep "spring - the cloud - the provider - 1.0. The jar" | grep -v grep | wc -l \ ` if \ [${already \ _run} - ne 0 \]. then echo "provider already Running!!!! Stop it first" exit -1 fi nohup Java -jar spring-cloud-provider-1.0.jar 1>stdout.log 2> &1&Copy the code

3. Add the stop.sh stop script

#! / bin/bash pid = \ ` ps - ef | grep "spring - the cloud - the provider - 1.0. The jar" | grep -v grep | awk '{print $2} \ ` kill SIGTERM $pid echo "process ${pid} killed"Copy the code

4. Add the cmdline command file

Java jar - spring - the cloud - the provider - 1.0. The jarCopy the code

It can be seen that both common application access and Mesh application access require some modification to access TSF, which is bound to bring some problems:

  1. Although the two access methods are small for a single microservice, but for large-scale applications of the project will be huge.

  2. For common application access, the TSF SDK dependency is introduced, and the TSF SDK dependency package conflicts with the service dependency package and causes version conflicts, that is, the service needs to find and modify the corresponding conflicting package version.

  3. Due to the introduction of TSF’s SDK dependencies, the business code is strongly coupled to the TSF platform, which is very unfriendly to users who do not want to be coupled to cloud vendor platforms.

Is there a way to access TSF without introducing TSF dependencies, modifying code, or reconstructing packages?

Native application access mode

The new VERSION of TSF (V1.28) is here!

Introduction of the third access method — native application access, support native Spring Cloud applications truly non-invasive access, no modification of a line of code, no recompilation, no rebuilding of the program package, existing application Jar package directly deployed access TSF!

Log in to the TSF console and deploy the native Spring Cloud application in four simple steps:

1. Create resource, VM cluster, or container cluster

2. Create an application and select [Native Application] as the application type.

3. Import the Jar package of the native Spring Cloud application or upload the image package

4. Create a deployment group to deploy native Spring Cloud applications

We know that Spring Cloud provides a rich service governance suite, but are these governance capabilities compatible with TSF? The following are the native governance capabilities supported by TSF, which basically cover common core capabilities:

In addition, TSF provides the following key capabilities:

  • Configuration file

  • Service statistic

  • Service routing

  • Service authentication

  • Service current limiting

Realize the principle of

You may wonder: how does TSF manage to make native applications enjoy the above rich service governance capabilities without any modification?

Let’s briefly introduce the basic principle of TSF native application access.

The following figure shows the simple invocation process of two Spring Cloud microservices through the Eureka registry. It can be seen that the starting point of service governance is the registry. Service providers register themselves in the registry, and service consumers obtain the list of service providers’ instances from the registry. And fusing gray, whole link service, routing, fault tolerance and load balancing governance capabilities are on the basis of the service provider instance list, so to realize these services management ability in the TSF first need to TSF access to the registry, and without changing the original application service registration and discovery code under the premise of how to implement?

Here, we introduce a Registry-proxy component, deployed in Sidecar mode on the Spring Cloud application side, and configure the address of the application registry to the address of the local Registry-Proxy. The application’s interaction requests with the original registry are referred to registry-proxy. Registry-proxy can receive each request sent to the registry and do the following according to each request:

  • Service registration request – Proxy registration to the TSF registry

  • Service discovery request – The proxy registry directly returns a list of instances containing only the service name of the service provider

  • Heartbeat report request – The agent reports the heartbeat to the TSF registry

It is easy to understand 1 and 3. Why does the proxy registry in 2 only return the service name?

We registered Spring Cloud applications to the TSF registry through a proxy registry. The next step is to implement runtime service governance. This is why we returned only the service name in 2, because the underlying service governance of native applications is implemented through TSF Mesh. Requests initiated by service consumers to service providers through service names are hijacked to the Mesh Sidecar deployed on the application side. In this way, the SidecAR can control the request traffic between services, namely, service fusing, whole-link gray scale, routing, fault tolerance, and load balancing.

Finally, after accessing TSF as a native application, the interservice invocation flow looks like this:

As the service governance of native applications is finally hosted by TSF Mesh for support, there is no requirement for the SDK version of Spring Cloud to be accessed. Versions E, F and G can be accessed and used as much as they like.

conclusion

The core of Spring Cloud microservice architecture is the development SDK framework and back-end support services such as registry Eureka. By introducing SDK dependencies and related service governance annotations, developers can quickly realize a microservice application. However, for back-end support services, especially to support large-scale microservice access in production environment, Will face great challenges; This is the value of the TSF microservices platform, which provides a powerful back-end support service capability, whether registry, data operations center, or service governance and control center, with industry-level high availability.

However, the two access modes provided by TSF have other problems to be optimized for native applications. Therefore, in order to reduce the threshold of Spring Cloud application access to TSF, completely get rid of the dependence on Cloud platform framework, and decoule users from Cloud vendors, TSF launched the native application access mode, which can enjoy TSF’s various powerful service governance capabilities without any modification!

Phase to recommend

Embrace Agent, “0” code to play Trace OpenTelemetry series second bomb!

The Agile Development Process of TSF, Tencent’s micro service platform

6 Steps for Front-end Programmers to Transform Microservices Architecture