Dubbo admin officially supports 3.0 service governance

Keywords: Java Distribution

Introduction: Dubbo is no stranger to you. It is a microservice development framework, which provides two key capabilities: RPC communication and microservice governance. In daily development, we use more RPC communication capabilities provided by Dubbo, but less service governance capabilities. This paper will focus on service governance. Dubbo framework provides extremely rich service governance functions, such as flow control, dynamic configuration, service Mock, service testing and so on. The role of Dubbo admin is to provide an out of the box platform for the service governance capabilities provided by Dubbo framework. This article will introduce the functions provided by Dubbo admin, so that you can quickly understand and use Dubbo admin, and have a preliminary understanding of the service governance capabilities provided by Dubbo.

Author introduction

Cheng Lu, Java development engineer, middleware development enthusiast, pays attention to service governance.
Yan Hao, a contributor to Dubbo, focuses on RPC, service governance and other fields.

preface

dubbo is no stranger to you. It is a microservice development framework, which provides two key capabilities: RPC communication and microservice governance. In daily development, we use more RPC communication capabilities provided by dubbo, but less service governance capabilities. This paper will focus on service governance. dubbo framework provides extremely rich service governance functions, such as flow control, dynamic configuration, service Mock, service testing and so on. The role of dubbo admin is to provide a out of the box platform for the service governance capabilities provided by dubbo framework. This article will introduce the functions provided by dubbo admin, so that you can quickly understand and use dubbo admin, and have a preliminary understanding of the service governance capabilities provided by dubbo.

Service details

The service details will display the service information provided by dubbo service in the dimension of interface, including service provider, consumer information and metadata information of the service, such as the provided method name and parameter list. The latest version supports the application level discovery model provided by dubbo 3.0, and the registration source is distinguished by application level / interface level.

Dynamic routing

Dubbo admin provides three kinds of routing support, namely conditional routing, label routing and Mesh routing. The functions provided can easily realize the demands of service governance such as black-and-white list, cluster isolation and Canary publishing. The following will show the functions of this part one by one.

Conditional routing

Conditional routing can write some custom routing rules to meet the requirements of service governance, such as black-and-white list, read-write separation, etc. The routing rule plays the role of filtering the address of the target server before initiating an RPC call. The filtered address list will be used as the alternative address for the consumer to finally initiate an RPC call.

The following figure shows the implementation of a simple blacklist function. The meaning of the routing rule is to prohibit consumers with IP 172.22.3.91 from calling the service HelloService. The format of the conditional routing rule is: [service consumer matching condition] = > [service provider matching condition].

Label routing

Label routing divides one or more service providers into the same packet and restricts traffic to flow only in the specified packet, so as to achieve the purpose of traffic isolation. It can be used as the capability basis for blue-green publishing, gray-scale publishing and other scenarios. Create rules at the provider application level, and the corresponding static marks are dubbo.provider.tag=tag1 and @ DubboService(tag = "tag2").

Mesh routing

Mesh routing is a new routing rule launched by dubbo 3.0. It has extremely powerful functions. Using mesh routing can cover the functional scenarios of the two routes, and can also combine more complex routing scenarios.

Mesh routing divides the whole traffic management into two parts: VirtualService and DestinationRule. VirtualService matches the inlet traffic and DestinationRule matches the outlet traffic. The following will implement a case. By routing the hi method of the service HelloService through the input parameter number, the request with even input parameter is routed to the service with label v1, and the service with odd input parameter is routed to the service with label v2.

public interface HelloService {

   

    String hi(Integer number);


}

The service implementation returns the service provider port.

public class HelloServiceImpl implements HelloService {


    @Value("${dubbo.protocol.port}")

    private String port;


    @Override

    public String hi(Integer number) {


        return "hi " + number + ", my port is :" + port;

    }

}

Step 1: start two service providers. The parameters are port = 20883, dubbo.application.parameters.test-version = v1 and port = 20884, dubbo.application.parameters.test-version = v2. The parameters defined by dubbo.application.parameters will be exposed to the service URL.

dubbo.application.parameters.test-version = v1

dubbo.protocol.port=20883

Step 2: create a mesh routing rule, which defines VirtualService and DestinationRule. The DestinationRule section divides the service URL parameters test version = v1 and test version = v2 into services v1 and v2 respectively. VirtualService will match the input parameters of the HelloService#hi method of the service, route the even number to the v1 service, and route the odd number to the v2 service.

apiVersion: service.dubbo.apache.org/v1alpha1

kind: VirtualService

metadata:

  name: demo/oddEvenRouter

spec:

  dubbo:

  - routedetail:

    - match:

      - method:

          argc: 1

          args:

          - index: 0

            num_value:

              oneof:

              - exact: 0.0

                mod: 2.0

            type: int

          name_match:

            exact: hi

      name: even-route

      route:

      - destination:

          host: demo

          subset: v1

    - match:

      - method:

          argc: 1

          args:

          - index: 0

            num_value:

              oneof:

              - exact: 1.0

                mod: 2.0

            type: int

          name_match:

            exact: hi

      name: odd-route

      route:

      - destination:

          host: demo2

          subset: v2          

    services:

    - exact: org.test.apache.dubbo.interfaces.HelloService                                

---

apiVersion: service.dubbo.apache.org/v1alpha1

kind: DestinationRule

metadata:

  name: test-route

spec:

  host: demo

  subsets:

    - name: v1

      labels:

        test-version: v1

    - name: v2

      labels:

        test-version: v2

Step 3: start the consumer to test, and you can see the returned results. As we expected, a simple gray function is realized through the appeal case. Of course, it can also easily realize A/B test, Canary release and other functions.

Dynamic configuration

Dynamic configuration provides the ability to dynamically adjust the behavior of RPC calls without restarting. For example, modify timeout, weight, load balancing policy adjustment, service degradation, etc. This avoids the need to restart the service in order to adjust Dubbo parameters. Some common parameter adjustments are shown below.

Timeout adjustment, the timeout is adjusted to 6000 ms

configVersion: v2.7

enabled: true

configs: 

  - addresses: [0.0.0.0]  # 0.0.0.0 for all addresses

    side: consumer        # effective side, consumer or addresses

    parameters: 

      timeout: 6000       # dynamic config parameter

Weight adjustment

configVersion: v2.7

scope: application

key: demo-provider

enabled: true

configs:

- addresses: ["10.20.153.10:20880"]

  side: provider

  parameters:

    weight: 200

Load policy adjustment

configVersion: v2.7

scope: application

key: demo-consumer

enabled: true

configs:

- side: consumer

  parameters:

    loadbalance: random

Documentation and testing

Interface documentation

dubbo API docs is a tool for displaying dubbo interface documents and testing interfaces, which is equivalent to the role of swagger for RESTful Web services. Using this function requires the dubbo service to introduce related packages dubbo API docs annotations and dubbo API docs core to describe the interface and parameter information in the form of annotations.

<dependency>

    <groupId>org.apache.dubbo</groupId>

    <artifactId>dubbo-api-docs-annotations</artifactId>

    <version>${dubbo-version}</version>

</dependency>



<dependency>

    <groupId>org.apache.dubbo</groupId>

    <artifactId>dubbo-api-docs-core</artifactId>

    <version>${dubbo-version}</version>

</dependency>

The renderings are as follows

Service test

Compared with service testing, dubbo API docs can test dubbo services without introducing any dependencies, which is convenient for rapid adjustment and verification of dubbo services. The effect diagram is as follows:

Service Mock

The service Mock intercepts the Consumer's request to the Provider through no code embedding, and dynamically releases the Consumer's request or returns the user-defined Mock data. So as to solve the blocking problem caused by the Consumer developer when the Provider that the Consumer depends on is not ready in the early development process.

Just take the following two steps to enjoy the convenience brought by the service Mock function:

Step 1: the Consumer application introduces the service Mock dependency and adds JVM startup parameters-`

Denable.dubbo.admin.mock=true Open service Mock Function.

<denpendency>

    <groupId>org.apache.dubbo.extensions</groupId>

    <artifactId>dubbo-mock-admin</artifactId>

    <version>last</version>

</denpendency>

Step 2: configure the corresponding Mock data in Dubbo Admin.

Summary

This paper introduces most of the functions of dubbo admin, covering the whole stages of development, testing and online. I hope this article can bring some help to the use and start of dubbo admin. For detailed use details, please refer to the official website. I also hope dubbo admin can bring a new experience to dubbo users and make it easier and faster to use the service governance capabilities provided by dubbo.

Original link
This article is the original content of Alibaba cloud and cannot be reproduced without permission.

Posted by lepad on Mon, 06 Dec 2021 22:17:24 -0800