Configuration and principle of Dubbo

1. Introduction to Dubbo

Dubbo is a microservice development framework, which provides two key capabilities: RPC communication and microservice governance. This means that the micro services developed by Dubbo will have mutual remote discovery and communication capabilities. At the same time, the rich service governance capabilities provided by Dubbo can realize service governance demands such as service discovery, load balancing and traffic scheduling. At the same time, Dubbo is highly scalable. Users can customize their own implementation at almost any function point to change the default behavior of the framework to meet their business needs.

Dubbo provides a one-stop solution for building cloud native microservice business. You can use Dubbo to quickly define and publish microservice components. At the same time, based on Dubbo's rich out of the box features and strong expansion capabilities, Dubbo can build various service governance capabilities required for the operation and maintenance of the whole microservice system, such as Tracing, Transaction, etc. the basic capabilities provided by Dubbo include:

  • Service discovery

  • Streaming communication

  • load balancing

  • Flow control

  • .....

Dubbo provides almost all service governance capabilities from service definition, service discovery, service communication to traffic control, and tries to shield the underlying details from users in use to provide better ease of use.

 

2. Dubbo's architecture

 

Node role description:

  • Provider: the provider of the exposed service.

  • Consumer: the service consumer that calls the remote service.

  • Registry: the registry for service registration and discovery.

  • Monitor: the monitoring center that counts the number and time of service calls.

  • Container: service running container

 

Centralized components:

  • Registration center. Coordinate address registration and discovery between Consumer and Provider

  • Configuration center.

    • Store the global configuration of Dubbo startup phase to ensure the cross environment sharing and global consistency of the configuration

    • Responsible for storing and pushing service governance rules (routing rules, dynamic configuration, etc.).

  • Metadata center.

    • Receive the service interface metadata reported by the Provider and provide operation and maintenance capabilities (such as service testing, interface documents, etc.) for Admin and other consoles

    • As a supplement to the service discovery mechanism, it provides the synchronization ability of additional interface / method level configuration information, which is equivalent to the additional expansion of the registry.

 

3. Dubbo configuration (integrated use of Spring)

(1). Configure using XML

provider.xml example

 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
     <dubbo:application name="demo-provider"/>
     <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
     <dubbo:protocol name="dubbo" port="20890"/>
     <bean id="demoService" class="org.apache.dubbo.samples.basic.impl.DemoServiceImpl"/>
     <dubbo:service interface="org.apache.dubbo.samples.basic.api.DemoService" ref="demoService"/>
 </beans>consumer.xml Example
 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
     <dubbo:application name="demo-consumer"/>
     <dubbo:registry group="aaa" address="zookeeper://127.0.0.1:2181"/>
     <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.samples.basic.api.DemoService"/>
 </beans>

 

Label details:

labelpurposeexplain
label purpose explain
<dubbo:service/> Service configuration It is used to expose a service and define the meta information of the service. A service can be exposed with multiple protocols, and a service can also be registered with multiple registries
<dubbo:reference/> 2 Reference configuration Used to create a remote service proxy. A reference can point to multiple registries
<dubbo:protocol/> Protocol configuration It is used to configure the agreement information for providing services. The agreement is specified by the provider and passively accepted by the consumer
<dubbo:application/> Application configuration Used to configure the current application information, regardless of whether the application is a provider or a consumer
<dubbo:module/> Module configuration Used to configure current module information. Optional
<dubbo:registry/> Registry configuration Used to configure information about the connection registry
<dubbo:monitor/> Configuration of monitoring center Used to configure information related to connecting to the monitoring center. Optional
<dubbo:provider/> Provider configuration When a property of ProtocolConfig and ServiceConfig is not configured, this default value is adopted. Optional
<dubbo:consumer/> Consumer configuration When a property of ReferenceConfig is not configured, this default value is adopted; optional
<dubbo:method/> Method configuration Used to specify method level configuration information for ServiceConfig and ReferenceConfig
<dubbo:argument/> Parameter configuration Used to specify method parameter configuration

 

(2). Annotation configuration

service provider

Service annotation exposure service

@Service
public class AnnotationServiceImpl implements AnnotationService {
  @Override
  public String sayHello(String name) {
    return "annotation: hello, " + name;
  }
}

 

Add application sharing configuration

dubbo.application.name=annotation-provider

dubbo.registry.address=

dubbo.protocol.name=dubbo

dubbo.protocol.port=20880

 

Service consumer

Reference annotation reference service

@Component("annotationAction")

public class AnnotationAction {

@Reference

private AnnotationService annotationService;

public String doSayHello(String name) {

return annotationService.sayHello(name);

}

 

Add application sharing configuration

 dubbo.application.name=annotation-consumer
 dubbo.registry.address=zookeeper://127.0.0.1:2181
 dubbo.consumer.timeout=3000

 

 

Added by Tonata on Thu, 13 Jan 2022 15:45:37 +0200