As a popular RPC framework in China, dubbo’s basic principle and configuration tuning are often asked in interviews. Knowing these or knowing the existence of these configuration items will get twice the result with half the work. If you encounter similar questions, you can no longer ask a certain degree of advertising.

1. Introduction of Dubbo

Dubbo | ˈ d ʌ b goes ʊ | by alibaba is a open source, distributed RPC (Remote Procedure Call Protocol – a Remote Procedure Call) and micro service framework, and now the top Apache projects.

Dubbo provides three key features: interface-based remote invocation, fault tolerance and load balancing, and automatic service registration and discovery.

Dubbo makes calling a remote service as easy as calling a local Java service.

The structure of Dubbo is shown below:

The use of Dubbo can be found in the official documentation http://dubbo.apache.org.

2.Dubbo service exposure and consumption process

Let’s start with the following questions:

  1. The process by which a Dubbo service provider publishes a service

  2. Dubbo serves the process by which consumers consume services

  3. What is local exposure and remote exposure, and the difference

Dubbo service provider publishes service process:

Start with dubbo’s startup log:

The logs boxed from top to bottom are as follows:

  1. Expose service to local

  2. Expose service to remote

  3. Start the Netty service

  4. Connect the zookeeper

  5. Register the service with ZooKeeper

  6. Listen for consuming services in ZooKeeper

Implementation details of this process can be found in the Official Dubbo documentation -> Implementation Details -> Remote Invocation details -> details of how a service provider exposes a service. Screenshot below:

Dubbo service consumer consumption service process:

The implementation details of this process can be found in the Official Dubbo documentation -> Implementation Details -> Remote invocation details -> details of how a service consumer consumes a service. Screenshot below:

Here’s the difference between local and remote exposure:

Local exposure is exposure to the native JVM and calls to local services do not require network communication.

Remote exposure exposes information such as IP addresses and ports to remote clients, requiring network communication when invoking remote services.

3.Dubbo related agreements

Dubbo allows you to configure multiple protocols, support different protocols on different services or support multiple protocols simultaneously on the same service.

In terms of performance, different services apply different protocols for transmission. For example, short connection protocols are used for large data and long connection protocols are used for large concurrent small data.

Dubbo supports the following protocols:

Dubbo:

The default Dubbo protocol is the Dubbo protocol, which uses a single long connection and NIO asynchronous communication. It is suitable for service invocation with small data volume and large concurrency, and the number of service consumers is far greater than that of service providers.

Conversely, the default Dubbo protocol is not suitable for services that transmit large amounts of data, such as files and videos, unless the request volume is very low. rmi:

The RMI protocol uses blocking (synchronous) short connections and JDK standard serialization. Scope of application: incoming and outgoing parameters packet size mixed, the number of consumers and providers is about the same, can be transmitted files.

hessian:

Hessian uses Http communication (synchronization) and servlets to expose the service. It is suitable for large incoming and outgoing parameter data packets, more providers than consumers, greater pressure from providers, and transferable files.

Other protocols supported by Dubbo are HTTP, WebService, Thrift, memcached, and Redis

4. Configure Dubbo

Let’s start with the following questions:

What are the main configuration items of Dubbo and what are their functions?

If the server of Dubbo is not started, can the consumer be up?

Dubbo configuration items:

Configuring application information:

<dubbo:application name=”appName-provider” />

Configure registry information:

“Dubbo: registryid =” zk “protocol =” zookeeper “address =” 127.0.0.1:2181 “/ >

Configure the service protocol:

<dubbo:protocol name=”dubbo” port=”20880″ threadpool=”cached” threads=”80″ />

Configure all exposed service defaults:

<dubbo: Provider registry=”zk” protocol=”dubbo” retries=”0″ version=”1.0.0″ timeout=”3000″ Threadpool =”cached” threads=”4″/>

Configuring exposure services:

<dubbo:service interface=”com.orgname.app.serviceX” ref=”serviceX” />

Configure the default values for all reference services:

<dubbo: Consumer check=”false” timeout=”1000″ version=”1.0″ retries=”0″ async=”false” />

Configure the reference service:

Remark:

A. The default value of reference check is true. During startup, the system checks whether the referenced service already exists

The configuration of b. is all the default configuration, and is overridden by the configuration of. The same is true for all dubbo: services by default.

Annotation configuration:

Com. Alibaba. Dubbo. Config. The annotation. The Service configuration services

Com. Alibaba. Dubbo. Config. The annotation. The Reference configuration Reference service

All right, keep an eye out if you find anything. Welcome Java engineers who have worked for one to five years to join Java Programmer development: 854393687 group provides free Java architecture learning materials (which have high availability, high concurrency, high performance and distributed, Jvm performance tuning, Spring source code, MyBatis, Netty, Redis, Kafka, Mysql, Zookeeper, Tomcat, Docker, Dubbo, multiple knowledge architecture data, such as the Nginx) reasonable use their every minute and second time to learn to improve yourself, don’t use “no time” to hide his ideas on the lazy! While young, hard to fight, to the future of their own account!