preface

Hello everyone, today we start to share – Dubbo special Dubbo service online testing. In the previous chapter we introduced service governance in Dubbo, and we learned that Dubbo provides us with some common service governance capabilities, including tuning routing, label routing, whitelist, dynamic configuration, load balancing, and so on. We also learned how to use the Dubbo Admin console for service governance for our distributed services. In this section we will focus on Dubbo Admin’s ability to call services online in a way that allows us to test services online without writing our unit test cases. So let’s get started quickly!

1. Introduction to service online testing

Dubbo Admin gives us the ability to make remote service calls from the console by using our Dubbo generic calls to make remote service calls without requiring jar package dependencies. You can refer to the discussion on generalized reference in the previous chapter “Dubbo Generalized Reference”. Its core principle is to use the metadata of the service to make remote calls. The core API is GenericService.

2. Example demonstration

Let’s start our service online test demo. First we create a service provider with the following project structure:

Since only the service provider is required to provide the service, and the service provider is invoked in our Dubbo Admin, there is no need for the consumer side. Let’s look at the defined interface code:

/ * * *@author<a href="http://youngitman.tech"> Young IT male </a> *@versionV1.0.0 *@className BookService
 * @description
 * @JunitTest: {@link  }
 * @dateThe 2020-10-24 * * / supposing
public interface BookFacade {

   // Query all books
    List<Book> queryAll(a);

   // Filter books according to the request parameters
    default List<Book> queryByName(@NotNull RequestParameter request) {
        returnLists.newArrayList(); }}Copy the code

3. Service online testing

Let’s start the Dubbo Admin demo. First we find the entry to use:

We entered the name of the service side interface to search in the search box and found relevant metadata information as follows:

In the search results, we can see the method name, parameter list, and return value information in the exposed service interface. Next we test using the queryByName method and click the edit icon on the right to enter:

The Parameters above are our array of parameter lists, and the array elements for each location represent the method Parameters for that location. We enter here SpringBoot parameter name query to the results as a list, the list element types for com.muke.dubbocourse.com mon. Domain. The Book, The name value of the object is SpringBoot, and the desc value is SpringBoot actual combat.

4. Principle analysis

The core of Dubbo Admin service test is the method signature information, that is, method name, parameter list and return value type information. With these information, we can fill in values according to the parameters of corresponding methods and assemble a complete service consumer. The following figure can best illustrate the principle:

As you can see from the figure above, our service provider registers metadata information to the registry (metadata center can be a separate service), then Dubbo Admin pulls the metadata to display on the page, and we initiate the call to the remote service after configuring the service method parameters in Dubbo Admin. Let’s look at the metadata registered in ZooKeeper:

The Json format is as follows:

{
	"parameters": {Service provider configuration information
		"side": "provider"."release": "2.7.8"."methods": "queryByName,queryAll"."deprecated": "false"."dubbo": "2.0.2"."interface": "com.muke.dubbocourse.common.api.BookFacade"."generic": "false"."serialization": "hessian2"."metadata-type": "remote"."application": "demo-provider"."dynamic": "true"."anyhost": "true"
	},
	"canonicalName": "com.muke.dubbocourse.common.api.BookFacade".// Interface description
	"codeSource": "file:/Users/liyong/work/workspace/course/target/classes/".// Where the source code is located
  // All method information
	"methods": [{
		"name": "queryByName".// Method name
		"parameterTypes": ["com.muke.dubbocourse.common.api.RequestParameter"].// Method parameter type
		"returnType": "java.util.List\u003ccom.muke.dubbocourse.common.domain.Book\u003e"// Method return value type
	}, {
		"name": "queryAll"."parameterTypes": []."returnType": "java.util.List\u003ccom.muke.dubbocourse.common.domain.Book\u003e"}]."types": [{// All type description lists
		"type": "com.muke.dubbocourse.common.api.RequestParameter".// Method parameter type
		"properties": {// Describe all property fields
			"name": {
				"type": "java.lang.String"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"}},"typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"
	}, {
		"type": "java.lang.String"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"
	}, {
		"type": "com.muke.dubbocourse.common.domain.Book"."properties": {
			"name": {
				"type": "java.lang.String"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"
			},
			"desc": {
				"type": "java.lang.String"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"}},"typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"
	}, {
		"type": "int"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"
	}, {
		"type": "char"."typeBuilderName": "org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder"}}]Copy the code

Related to the service test above is the method and type information contained in methods and types, which Dubbo Admin displays on the console and asks the user to enter configuration parameter values.

5. Summary

In this section we learned about the online testing capabilities of services provided in Dubbo Admin. Dubbo Admin online test is implemented through Dubbo generalization call, and its core API is GenericService. The core of the whole online test is that we need the metadata of the service provider. According to the metadata information, we configure the parameters of the method to be called in Dubbo Admin, and then initiate the remote call.

The highlights of this lesson are as follows:

  1. Understand Dubbo Admin online tests

  2. Know how to use online tests

  3. Understand the implementation principles of online testing

The author

Personally engaged in the financial industry, I have worked in chongqing’s first-class technical team of Yiji Pay, Sijian Technology and an online car hailing platform, and now I am working in a bank responsible for the construction of unified payment system. I have a strong interest in the financial industry. It also practices big data, data storage, automated integration and deployment, distributed microservices, responsive programming, and artificial intelligence. At the same time, he is also keen on technology sharing, creating public accounts and blog sites to share knowledge system. Concern public number: young IT male get latest technical article push!

Blog: Youngitman.tech

Wechat Official Account: