I. Case description

Dubbo is a distributed, high-performance, transparent RPC service framework that provides efficient service governance solutions such as automatic service registration and automatic discovery. Dubbo’s Chinese documentation is also very comprehensive, as shown in the following figure:

Second, Dubbo basic introduction and environment construction

1. Basic introduction to Dubbo

Changes in Dubbo’s management structure are shown in the following figure:

Dubbo service can be well monitored through the Dubbo monitoring center and background management, monitoring the service and client call situation, call times, call logs, convenient problem search.

2. Environment construction

Install zookeepe and decompress zookeeper-3.4.8.tar.gz.



Then go to conf and rename zoo_sample. CFG to zoo.cfg. And relevant contents are as follows:


This directory is the directory for storing data. Then start in the bin directory:



3. Project creation

1. Build project B

1. Import dependencies


2. Create an object


3. Create a service


4. Write a Configuration file for Dubbo

Dubbo /dubbo-server.xml in the root directory:


5. Write Web. XML

6. Start tomcat

You should see the following on the console:


You can see that the UserService service has been registered with the ZooKeeper registry and the protocol is dubbo.


2. Build project A

1. Copy basic files

Copy the User object and UserService interface from system B to system A

.

2. Write a Configuration file for Dubbo

3. Write UserService test cases

The result is as follows:

It can be seen that 10 pieces of data have been queried, so that means that system A has obtained data through the service provided by system B.

3, solve the problem of code duplication

As we can see, in the above case, both the User entity and the service interface are needed, and the code reuse is not high. This part of the code can then be extracted and packaged for use by all systems. So you can create a project called Dubo-B-API. Then put all the relevant code in that project and import the project dependencies in other projects. This is what we would do in a real project, because the caller may not know the details.