I don’t know if you’ve ever been in a similar situation at work:
-
Debugging the Dubbo interface is complex and needs to be triggered by Telnet commands or consumer calls.
-
Telnet statement parameter format is complex, each time to write carefully, once mistakes need to be repeated.
-
The interface for parameter transmission and call of complex objects is complex, and it costs a lot of time to write Java API to call the interface.
I have encountered all these pits in my work, and found that most of the time would be stuck in the stage of calling dubbo service to do self-testing, so I later spent my spare time to write an efficient Dubbo testing tool open source for everyone to use.
This tool has been applied in practical work for more than half a year, and its basic functions are mature. Version maintenance will be carried out in the future.
The relevant code address is:
Gitee.com/IdeaHome_ad…
Ps: If you like it, I hope you can give me a precious star
About how to deploy this tool
After downloading the GitLab code, you will see two file packages: iubo-Proxy and iubo-proxy-Web, which correspond exactly to the back-end and front-end code, respectively.
Deployment of front-end code
The front end uses very simple VUE technology and just needs to deploy files on an Nginx to work. The default access page for the front end is test-dubo-web.html.
However, there are two minor changes to the JS configuration
constants.js
In this file, the corresponding request server address is written, and this is the URL corresponding to the back-end service.
Since requesting the dubbo interface requires pulling the service list through the ZK registry, you need to configure it in commonZk in iubbo.
The host is an alternate name for a key used by the front end for display, but actually transmitted to the back end with the IP value.
Deployment of back-end code
The backend uses springboot framework technology, and the core configuration is stored in application.properties:
server.port=7089 application.invoker.name=iubbo-invoker-proxy spring.datasource.druid.password= Spring. The datasource. The druid. Username = spring. The datasource. The druid. Url = JDBC: mysql: / / 127.0.0.1:3306 / iubbox - proxy spring.datasource.druid.driver-class-name=com.mysql.jdbc.Driver mybatis-plus.configuration.map-underscore-to-camel-case=trueSpring. Redis. Port = 6379 spring. Redis. Host = 127.0.0.1Copy the code
SQL > create table SQL > create table
CREATE TABLE `t_dubbo_invoke_req_record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL COMMENT 'user id',
`arg_json` varchar(2500) COLLATE utf8_bin DEFAULT NULL COMMENT 'Dubbo request Parameters',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `t_user` (
`id` int(9) NOT NULL AUTO_INCREMENT,
`username` varchar(60) COLLATE utf8_bin DEFAULT NULL,
`password` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`createTime` datetime DEFAULT CURRENT_TIMESTAMP,
`updateTime` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
Copy the code
-
The t_user command is used to record user accounts, facilitating the saving of user account information.
-
T_dubbo_invoke_req_record Records the use case information that requests the Dubbo interface.
The last is to start the entry class org. Iubbo. Proxy. DubboInvokerApplication
Startup Screenshot
About the use of this tool tutorial
The tool distinguishes the roles of the logged in account and the unlogged account. Users of the logged in account can save the requested use cases for the convenience of retrieving information next time. Although the unlogged account does not have the function of saving use cases, it does not affect their use of the tool for testing.
Home page screenshot:
1. Specify the ZK address
Before testing the dubbo interface, we usually pull the service address on the zK. The operation is as follows: First click in the text box, enter the letters or numbers related to the JS configuration, and there will be fuzzy matching options for you to choose:
After the zK address is selected, click the zK address button again (some colleagues just touched this tool, it was confused ~~)
When pulling the ZK address, the back end will pull it according to the IP value in the JS configuration mentioned above.
Next comes the ability to filter the address of the Dubbo service, with a drop-down box below the zK address, which should be injected with the names of all the Dubbo service lists on the ZK.
Select the appropriate service name, and then enter the method name for this interface in the Please Enter a name text box on the right.
Here’s an example of calling the sendMsg method of MsgService:
Then configure parameters and names
Select the corresponding parameter type and value:
Finally make a request:
Next to the basic parameter configuration items, there is a module dedicated to configuring the additional content of the Consumer side. These parameters are the scenarios that might be used in daily work, and can be configured as needed. There is also a direct connection option that is very common at work.
My personal favorite is the direct connection feature, because during development, the direct connection machine is often required to test itself:
If you want to save the dubbo test case you sent, you need to log in to the account and write a data item directly to the t_user table:
At the top right of the home page is a login button:
Click login
How to save the request use case:
There are some minor flaws in saving the use case, which requires the user to manually refresh the page to display the saved use case information:
Click Select parameters and the page will display the previously used request information again.
Special parameter request
The tool supports invocation of a variety of parameter formats common to development, and currently supports regular parameters
Ps: Note that the parameter format must be mapped in the same order and type as the parameter format in the dubbo method, otherwise the backend program will return that the corresponding method cannot be found
Common basic types of Java data: Boolean, short, int, long, double, char, float
Common wrapper class data in Java:
java.lang.String,
java.lang.Integer,
java.lang.Object,
java.util.List,
java.lang.Class,
java.lang.Long,
java.lang.Boolean,
java.util.Map,
java.util.Date,
java.lang.Float,
java.lang.Double
Copy the code
For simple data type passing
Multi-parameter, Chinese and English mixed transmission
Passing of arguments of type List
Class parameter passing
Parameter passing of Map type
Parameter passing of type Date
User-defined object parameters are passed
If the following interface is called in a real-world scenario, then this use would require a custom parameter:
Complex type custom parameter passing
Suppose a List argument is encountered and the passed List contains a custom object, such as the following:
List<UserDTO> testUserDtoList(List<UserDTO> userDTOList,Class clazz);
Copy the code
The case can be written as follows:
Easy to generalize
Note that the order of the parameters of the request should be the same as the order of the parameters of the method. Assume that the method definition of the service is as follows:
<T> List<T> getList(List<Long> var1, Class<T> var2);
Copy the code
The argument passed in must be a List argument followed by a Class argument.
-
Correct example :(first List argument, then Class argument)
-
Example error :(write the Class argument first, then write the List argument)