Basic configuration of dubbo

1 Overview

Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation solutions and SOA service governance solutions. The main core component
Remoting: network communication framework, which implements sync-over-async and request-response message mechanisms.
RPC: An abstraction of remote procedure calls, supports load balancing, disaster tolerance and cluster functions.
Registry: Service catalog framework for services Registration and service event publishing and subscription.
Dubbo adopts the full Spring configuration method, transparent access to the application, without any API intrusion to the application, just use Spring to load the Dubbo configuration, and Dubbo is loaded based on Spring's Schema extension.
Insert picture description here

2. Frame

Insert picture description here
Node role description:
Provider: The service provider that exposes the service.
Consumer: The service consumer who calls the remote service.
Registry: The registry for service registration and discovery.
Monitor: A monitoring center that counts the call times and call times of the service.
Container: The service running container.
Calling relationship description:
0 The service container is responsible for starting, loading, and running the service provider.

  1. When the service provider starts, it registers the service it provides with the registration center.
  2. When a service consumer is started, he subscribes to the registry for the service he needs.
  3. The registration center returns the list of service provider addresses to the consumer. If there is a change, the registration center will push the change data to the consumer based on the long connection.
  4. Service consumers, from the provider address list, based on the soft load balancing algorithm, select one provider to call, and if the call fails, select another to call.
  5. Service consumers and providers accumulate the number of calls and call time in the memory, and send statistical data to the monitoring center every minute.

3. Basic configuration

<dubbo:service/> 服务配置,用于暴露一个服务,定义服务的元信息,一个服务可以用多个协议暴露,一个服务也可以注册到多个注册中心。
eg、<dubbo:service ref="demoServiceImply" interface="com.unj.dubbotest.provider.DemoService" />
说明:interface是服务接口的绝对路径;ref服务接口实现类名(首字母小写)

<dubbo:reference/> 引用服务配置,用于创建一个远程服务代理,一个引用可以指向多个注册中心。
eg、<dubbo:reference id="demoService" interface="com.unj.dubbotest.provider.DemoService" />
说明:id是要调用的接口(DemoService)的名字(首字母小写);interface是接口的绝对路径;

<dubbo:protocol/> 协议配置,用于配置提供服务的协议信息,协议由提供方指定,消费方被动接受。
说明:如果需要支持多协议,可以声明多个<dubbo:protocol/>标签,并在<dubbo:service/>中通过protocol属性指定使用的协议。
eg、<dubbo:protocol name="dubbo" port="20880" />

<dubbo:application/> 应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
用于注册中心计算应用间依赖关系。
eg、<dubbo:application name="xixi_provider" />
    <dubbo:application name="hehe_consumer" />

<dubbo:module/> 模块配置,用于配置当前模块信息,可选。
<dubbo:registry/> 注册中心配置,用于配置连接注册中心相关信息。
eg、<dubbo:registry address="zookeeper://192.168.2.249:2181" />

<dubbo:monitor/> 监控中心配置,用于配置连接监控中心相关信息,可选。

<dubbo:provider/> 提供方的缺省值,当ProtocolConfig和ServiceConfig某属性没有配置时,采用此缺省值,可选。
说明:该标签为<dubbo:service><dubbo:protocol>标签的缺省值配置。

<dubbo:consumer/> 消费方缺省配置,当ReferenceConfig某属性没有配置时,采用此缺省值,可选。
说明:该标签为<dubbo:reference/>标签的缺省值设置。


<dubbo:method/> 方法配置,用于ServiceConfig和ReferenceConfig指定方法级的配置信息。
说明:该标签为<dubbo:service/><dubbo:reference/>的子标签,用于控制到方法级。
<dubbo:argument/> 用于指定方法参数配置。
说明:该标签为<dubbo:method/>的子标签,用于方法参数的特征描述。

4. Configure priority

Insert picture description here
The above figure takes timeout as an example to show the search order of the configuration. Other retries, loadbalance, actives, etc. are similar.

  • The method level takes precedence, the interface level is second, and the global configuration is again.
  • If the level is the same, the consumer will be given priority and the provider will be second.

5.group and version

Interface, group, and version are service matching conditions, and the three determine whether they are the same service.

5.1 group in dubbo

There are two places in dubbo to configure the group,
<dubbo:registry group="testgroup1" …
here the group represents your logical grouping, corresponding to a node of zk, when the consumer calls the provider, it finds all alive through this node Of service.

<dubbo:service group="a" interface="com.qunar.pay.OrderService" ref="aOrderService" />

<dubbo:service group="b" interface="com.qunar.pay.OrderService" ref="bOrderService" />

Group can also be configured here, which is used to identify the situation where a service interface has multiple implementations.
The same is true when the consumer makes calls. There is also a group on <dubbo:reference, which corresponds to the group on the service, not the group on the registry.

5.2version

When there is an incompatible upgrade in the implementation of an interface, the version number can be used for transition, and services with different version numbers do not refer to each other;

6.dubbo startup check

By default, Dubbo will check whether the dependent service is available at startup, and throw an exception when it is unavailable to prevent Spring initialization from completing so that problems can be found early when it goes online. The default check=true.
If your Spring container is lazily loaded or the service is delayed through API programming, please turn off check. Otherwise, when the service is temporarily unavailable, an exception will be thrown and a null reference will be obtained. If check=false, the reference will always be returned. When the service is restored, it can be automatically connected.
You can turn off the check with check="false". For example, during the test, some services do not care, or there is a circular dependency, and one party must start it first

关闭某个服务的启动时检查:(没有提供者时报错)
<dubbo:reference interface="com.foo.BarService" check="false" />

关闭所有服务的启动时检查:(没有提供者时报错)
<dubbo:consumer check="false" />

关闭注册中心启动时检查:(注册订阅失败时报错);前面两个都是指订阅成功,但提供者列表是否为空是否报错,如果注册订阅失败时,也允许启动,需使用此选项,将在后台定时重试。
<dubbo:registry check="false" />
     引用缺省是延迟初始化的,只有引用被注入到其他Bean,或被getBean()获取,才会初始化。
      如果需要饥饿加载,即没有人引用也立即生成动态代理,可以配置:

<dubbo:reference interface=“com.unj.dubbotest.provider.DemoService” init=“true” />

7. Configure dubbo cache file

The configuration method is as follows:

<dubbo:registryfile=”${user.home}/output/dubbo.cache” />

Note:
The path of the file can be adjusted by the application as needed to ensure that the file will not be cleared during the publishing process. If there are multiple application processes, be careful not to use the same file to avoid content being overwritten.
This file will be cached:
List of registry
service provider list
With this configuration, when the application restarts and the Dubbo registry is unavailable, the application will read the information of the service provider list from this cache file to further ensure the application reliability.

Guess you like

Origin blog.csdn.net/wenmin_111/article/details/113121768