Dubbo 3 in-depth analysis - know you through the source code | HD network disk

Link: https://pan.baidu.com/s/1d6YONkCi4u7T1ZBm1yZLYg Extraction code: iamh
Author - \ / 307570512

Introduction to Dubbo 3

Apache Dubbo is a high-performance, lightweight open source service framework. Apache Dubbo 3.0.0 was officially released - fully embracing cloud native

Since Apache Dubbo opened its source in 2011, it has accumulated a lot of experience in the practice of many large-scale Internet and IT companies. Dubbo has achieved great success in the past with its advantages of Java user-friendly, rich functions and strong governance ability, and has become one of the popular mainstream RPC frameworks at home and abroad.

However, with the advent of the cloud native era, Java microservice governance systems represented by Apache Dubbo and Spring Cloud are facing many new requirements, including the expectation that applications can start faster, the protocol penetration of application communication can be higher, and the support for multiple languages can be more friendly. For example, Spring also launched its Spring Native Beta solution based on GraalVM this year, with optimization improvements such as millisecond startup capability and higher processing performance.

This background puts forward two requirements for the next generation Apache Dubbo: one is to retain the advantages accumulated under the background of out of the box and landing practice, which is also expected by many developers; Second, follow the cloud native idea as much as possible to better reuse the underlying cloud native infrastructure and better fit the cloud native microservice architecture.

Apache Dubbo3 has been comprehensively upgraded compared with version 2.7. The following are some new core features:

New service discovery model
Compared with the service discovery mechanism based on interface granularity in version 2.x, 3.x introduces a new service discovery mechanism based on application granularity. The new model brings great advantages in two aspects:

It further improves the performance and stability of Dubbo3 in large-scale cluster practice. The new model can greatly improve the system resource utilization, reduce the single machine memory consumption of Dubbo address (50%), reduce the storage and push pressure of registry cluster (90%), and Dubbo can support the cluster scale to step into the level of one million instances.
Get through the addresses of other heterogeneous micro service systems and find obstacles to each other. The new model enables Dubbo 3 to realize interworking with heterogeneous micro service systems such as Spring Cloud, Kubernetes Service and gRPC at the address discovery level, and provides a feasible scheme for connecting Dubbo with other micro service systems.
In the early version of Dubbo 3, support will be provided for two sets of address discovery models at the same time to ensure the compatibility of service upgrades to the greatest extent.

Next generation RPC communication protocol
A new RPC communication protocol - Triple is defined. In one sentence, triple: it is an RPC Protocol Based on HTTP/2. It is fully compatible with gRPC and extends richer semantics on this basis. Using the triple protocol, users will gain the following capabilities

It is easier to adapt to the gateway and Mesh architecture. The Triple protocol makes it easier for Dubbo to work with various gateways and Sidecar components.
It is multilingual and friendly. It is recommended to use Triple protocol with Protobuf, use IDL to define services, and use Protobuf to encode business data.
Streaming communication support. The Triple protocol supports Request Stream, Response Stream and Bi direction stream

Cloud primordial
The business applications built by Dubbo 3 can be directly deployed on VM, Container, Kubernetes and other platforms. Dubbo 3 solves the problem of life cycle alignment between Dubbo service and scheduling platform, and the binding between Dubbo service discovery address and Container platform.

At the service discovery level, Dubbo3 supports the integration with Kubernetes Native Service, which is currently limited to Headless Service.

Dubbo 3 plans two forms of Service Mesh schemes. Dubbo will have Mesh schemes to choose from under different business scenarios, different migration stages and different infrastructure support, which can be further managed through a unified control surface.

Classic Sidecar based Service Mesh
Proxyless Mesh without Sidecar
The routing rules familiar to users in Dubbo 2 will be replaced by a set of unified traffic management rules in 3.x. This set of unified traffic rules will cover various deployment forms such as Service Mesh and SDK of Dubbo 3 in the future to realize the management of the whole micro service system.

Extension point separation
Some changes have also taken place in maven of dubbo 3. org.apache.dubbo:dubbo:3.0.0 will no longer be an all in one package containing all resources. Some optional dependencies have been published separately as independent components. Therefore, if users use independent components that are not in the dubbo core dependency package, such as registry etcd, RPC Hessian, etc, Dependency packages need to be added separately in pom.xml for these components.

The implementation of Zookeeper extension is still in the core dependency package, and the dependency remains unchanged

<properties>
    <dubbo.version>3.0.0</dubbo.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo</artifactId>
        <version>${dubbo.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo-dependencies-zookeeper</artifactId>
        <version>${dubbo.version}</version>
        <type>pom</type>
    </dependency>
</dependencies>

Redis extension implementation is no longer in the core dependency package. If redis related functions are enabled, the dependency package needs to be added separately

<properties>
    <dubbo.version>3.0.0</dubbo.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo</artifactId>
        <version>${dubbo.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo-dependencies-zookeeper</artifactId>
        <version>${dubbo.version}</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.apache.dubbo</groupId>
        <artifactId>dubbo-registry-redis</artifactId>
        <version>${dubbo.version}</version>
    </dependency>
</dependencies>

Service flexibility
Dubbo 3.0's flexibility enhancement takes failure oriented design as the concept, provides support including accurate capacity evaluation, adaptive current limiting and adaptive load balancing, and builds large-scale reliable applications step by step from bottom to top. From the perspective of single service, service is indestructible and stable. From a distributed perspective, complex topology will not bring performance degradation. Distributed load balancing can dynamically allocate traffic in an optimal way to ensure that heterogeneous systems can reasonably allocate requests according to the accurate service capacity at runtime, so as to achieve optimal performance

Comprehensive performance improvement
Compare the 2.x version with the Dubbo3 version

Service discovery resource utilization has increased significantly.
Compared with interface level services, it is found that the resident memory of a single machine decreases by 50%, and the GC consumption in the address change period decreases by an order of magnitude (100 times - > 10 times)
Compared with application level services, it is found that the resident memory of a single machine decreases by 75% and the number of GC tends to zero
Dubbo protocol has the same performance, and Triple protocol has more advantages in gateway and Stream throughput.
Dubbo protocol (3.0 vs 2.x). Compared with 2.x, the overall qps rt of 3.0 is flat and slightly improved
Triple protocol vs Dubbo protocol. In the scenario of direct connection call, triple has no advantage in performance. Its advantage lies in the scenario of gateway and Stream call.

Dubbo 3 in-depth analysis - know you through the source code - Apache Dubbo 3 source code analysis in simple terms

Service provider
Create an empty project and create a maven project (packaged as war) dubcodemo_ Provider module, import the following coordinates in pom.xml file

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <spring.version>5.0.2.RELEASE</spring.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <!-- dubbo relevant -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>zookeeper</artifactId>
        <version>3.4.7</version>
    </dependency>
    <dependency>
        <groupId>com.github.sgroschupf</groupId>
        <artifactId>zkclient</artifactId>
        <version>0.1</version>
    </dependency>
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.47</version>
    </dependency>
</dependencies>

Step 2: write the spring configuration file applicationContext-dubboprovider.xml of the service provider integrating spring and dubbo

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!--Name the current service provider-->
    <dubbo:application name="dubbodemo_provider"/>
    <!--appoint zookeeper Registry address and port,If using redis be address use redis of address-->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" ></dubbo:registry>
    <!--Protocol must use dubbo,A port number is a port that provides a consumer with access to it-->
    <dubbo:protocol name="dubbo" port="20881"/>
    <!--Enable annotation scanning so that dubbo The annotation of the is effective-->
    <dubbo:annotation package="com.alibaba.provider"/>
    
</beans>

Step 3: configure the project load listener in web.xml and specify the path of the spring configuration file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

  <!-- The listener listens to others spring configuration file -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

Step 4: write the interface and implementation class of the service
Service interface code

public interface HelloService {
    public String sayHello(String name);
}
 Service Implementation class code

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.service.provider.HelloService;
//This annotation uses Alibaba's dubbo annotation
@Service
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(String name) {
        return "hello@@"+name;
    }
}

Keywords: Java Microservices Cloud Native

Added by Salis on Thu, 21 Oct 2021 07:21:25 +0300