1. Introduction of Dubbo3
I won’t introduce how to use Dubbo. I will only mention it and then talk about how to test the Dubbo service. In addition to maintaining the classic architecture of 2.x, Dubbo3 also takes the process communication of microservices as its main responsibility, and uses rich service governance capabilities to better manage and control microservice service clusters. The abbreviation is even more awesome, and the original functions are still there. .
Dubbo’s calling process is as follows:
The overall process can be roughly divided into the following 11 steps (The default communication method Netty is summarized below Content):
- First the service provider will start, and then register the service to the service registration center (At this time, the host, port and other metadata of the service are in the registration center, except for the netty service In addition to information, interfaces marked with @DubboService will also be registered as services);
- The service consumer will periodically pull the service provider list;
- When the service consumer needs to call the service provider interface, because it cannot directly call the provider's interface remotely, it needs to generate a dynamic proxy object and then call the remote interface through this proxy object.
- After generating the proxy object, it will go to the Cluster layer, where the data of the service provider list will be obtained, and the service providers that can be called currently will be sensed;
- Then Cluster will perform load balancing based on the specified algorithm and select the service provider to be called;
- Exchange will encapsulate the request data according to the specified protocol format and encapsulate it into a request request;
- After the request is encapsulated, the request will be sent out through the network communication framework (TCP, long connections, everyone knows it) ;
- The service provider generally has a network communication framework, which will listen to the specified port number and deserialize the request after receiving the request;
- After deserialization, the request is parsed according to the specified protocol format according to Exchange;
10. Then the corresponding interface of the service provider is called through the dynamic proxy object.
2. List of Dubbo interface debugging methods
There are probably only two Dubbo service debugging methods that can be found online. If I say it forcefully, I can list three:
- Telnet
- Jmeter
- Write service consumer side for testing
Let’s talk about my personal feelings about him. What’s wrong:
-
The Telnet tool is very simple to use. It is carried by Windows itself. You can just type the command directly and then test the corresponding service. However, it cannot be combined with the registration center. From my personal use point of view, it cannot be better without integrating the personal center. Service governance, which is often divorced from actual development. The main thing is not visualization! ! !
-
Jmeter: Jmeter is undoubtedly a powerful testing tool. It cannot test Dubbo itself, but you can use the open source Jmeter-plugins-for-apache-dubbo plug-in on github. What is the regret? But it does not support 3.x. The official website explains as follows (of course I have also tested it for you):
-
emmmm, write the dubbo service consumer side and then test it. This...the process between the two services should be written before testing, right? My coding ability is not that strong yet, so I prefer to write part and test part; and this is not easy to test for multi-person development.
But I was lucky. I had nothing to do last night and wanted to read other people’s technical blog posts, and look what I saw:
Look what was mentioned in it, last night As you can see, I shared this after testing it when I had time today:
(It should be supported recently. I can’t find the version iteration of apifox. The latest one is 2.3.24. , the official website says that apifox needs >=2.3.10 to support it)
No matter, let’s use it first.
3. Apifox Debugging Dubbo Project
Focusing on testing, we use nacos as the registration center for testing. How to debug the Dubbo service in Apifox:
Service provider code
Configuration file
server:
port: 8082
spring:
application:
name: dubbo-provider-test
datasource:
password: 123456
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatisplus
mybatis-plus:
type-aliases-package: com.example.mp1.entity
mapper-locations: classpath:/mapper/**/*.xml
global-config:
banner: false
db-config:
id-type: assign_id
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
dubbo:
protocol:
name: dubbo
port: -1
application:
name: dubbo-test
registry:
address: nacos://127.0.0.1:8848
username: nacos
password: nacos
register: true
nacos:
config:
server-addr: 127.0.0.1:8848
Service interface
public interface DubboTestService {
User getUserById(Long id);
}
Service implementation
@DubboService
@Service
public class DubboTestServiceImpl implements DubboTestService {
@Autowired
UserService userService;
@Override
public User getUserById(Long id) {
User user = userService.getById(id);
return user;
}
}
After starting the service, the nacos service list is as follows:
Apifox test
First, create a Dubbo project, which is a module used to test the Dubbo service.
Import the Dubbo application data. This application refers to the application you configured in the configuration file. To put it bluntly, the metadata information of the netty service is finally stored in the service name in the nacos configuration center.
Fill in the application information and then import it
Then you can see the corresponding service in the interface management, easy!
When testing, remember to fill in the corresponding service ip:port, because it is used to make remote calls. Encapsulate it and write the request data to the netty service, and then respond back with the final result. Isn't this what long connections do? Is it a communication job?
Isn't that great?
What if you don't use the registration center? It can also be tested, but you have to write the service interface and methods yourself, then fill in the ip:port of the service, and then test. With this graphical interface, testing is much more convenient.
4. Long data transmission may cause accuracy loss
Because some of the data in my table was generated by the snowflake algorithm, and when I tested it, I found that the accuracy was lost, so I went to find out more about it.
This is because Dubbo uses Hessian as the serialization protocol by default, and Hessian will cause precision loss when serializing long integer data.
Let me show you the test:
Look, there is this record in my table. The first column is the id:
Here, do a Service test:
It can be found that the original 1710123046640713730 has become 1710123046640713728, 2 is missing, that is, the accuracy is lost.
Solution:
- Solve the problem essentially by changing it to the String type so that there will be no loss of precision.
- Customize the serialization method, or use Dubbo's other serialization protocols that will not cause loss of precision.
emmmm, this can be regarded as experience gained from testing.