Dubbo-- Configuration

First, the configuration guidelines

  -D priority JVM startup parameters, so users can deploy and start rewriting parameters, such as when starting the need to change the port protocol.

  XML second, if there is configured in XML, the corresponding configuration items dubbo.properties invalid.

  Properties Finally, the equivalent of the default value, only when there is no XML configuration, dubbo.properties corresponding configuration items take effect, usually used to share a common configuration, such as the application name.

  

 

Second, start checking

  By default, dubo checks whether the dependent service is available at startup. When fully initialized Spring is not available, it throws an exception in order to prevent Spring initialization is complete, in order to publish the application (the default setting) early detection of problems before: check=true.

  You can turn off the check check=false... For example, some services do not care about it when you run a test, or because of circular dependencies, you must first start the test.

  In addition, if Springbean is lazy loading, or use the API programming delay the referral service, turn off the check, otherwise the service will throw an exception when the service is temporarily unavailable, and then get a null reference. If you configure check=false, you can get a letter of recommendation. After the restore service, the service can automatically reconnect.

   2.1 Spring configuration file

    Disable service startup check (throw some anomalies / errors when no provider):

<dubbo:reference interface = "com.foo.BarService" check = "false" />

    Disable all services start checking (throw some exception / error is not provided):

<dubbo:consumer check = "false" />

    Disable registry startup checks (Sign up for failure error):

<dubbo:registry check="false" />

  2.2 dubbo.properties

dubbo.reference.com.foo.BarService.check = false
dubbo.reference.check = false
dubbo.consumer.check = false
dubbo.registry.check = false

  2.3 Use the -d parameter

java -Ddubbo.reference.com.foo.BarService.check = false
java -Ddubbo.reference.check = false
java -Ddubbo.consumer.check = false
java -Ddubbo.registry.check = false

 

Third, the time-out

  Due to network or server unreliable results in a call center appears an uncertain state (time-out). To avoid a timeout causes the client resource (thread) hang depleted, you must set the timeout. (Default 1 second)

  3.1 dubbo consumer side

Global timeout configuration
 < Dubbo: Consumer timeout = "5000"  /> 

specified interface and a specific configuration method timed 
< Dubbo: Reference interface = "com.foo.BarService" timeout = "2000" > 
    < Dubbo: Method name = "the sayHello" timeout = "3000"  /> 
</ Dubbo: Reference >

  3.2 dubbo server

Global timeout configuration
 < Dubbo: Provider timeout = "5000"  /> 

specified interface and a specific configuration method timed 
< Dubbo: Provider interface = "com.foo.BarService" timeout = "2000" > 
    < Dubbo: Method name = "the sayHello" timeout = "3000"  /> 
</ Dubbo: Provider >

  3.3 Configuration Guidelines

    3.3.1 dubbo recommended configuration as much as possible on the Provider Consumer-side properties:

    1, the provider for services, better than service consumer service performance parameters, such as calling a timeout, a reasonable number of retries, etc.

    2, in the configuration Provider, not Consumer Provider Configuration value is used, i.e., as a default configuration may Provider Consumer's. Otherwise, use the global settings Consumer Consumer end, which for Provider uncontrollable and often irrational

    3.3.2 configuration override rule

    1, a method other than the interface level level configuration, i.e. small Scope priority

    2, Consumer-side configuration better than global configuration Provider configuration,

    3, the final configuration is Dubbo Hard Code

  

 

Fourth, the number of retries

  When a failure occurs, the retry another server (the default). Idempotent operations typically used, but will result in a longer retry delay. Retry time can retries =2(except the first time)

  Configuration:

<dubbo:service retries="2" />

  or:

<dubbo:reference retries="2" />

  or:

<dubbo:reference>
    <dubbo:method name="findFoo" retries="2" />
</dubbo:reference>

  Idempotent and non-idempotent difference: https://www.cnblogs.com/lzc978/p/10386122.html

 

Fifth, the version number

  When the interface is not compatible upgrade, you can use the version number of the conversion. Different versions of the service does not refer to each other. (Gray-release)

  Version can be migrated by following these steps:

  1. In the low-pressure stage, upgrade to half provider to the new version.
  2. Then all consumers will upgrade to the new version.
  3. And then upgrade the rest of the half provider to the new version.

  The old version 5.1 Service Provider configurations:

<dubbo:service interface="com.foo.BarService" version="1.0.0" />

  5.2 新版本的服务提供者配置:

<dubbo:service interface="com.foo.BarService" version="2.0.0" />

  5.3 服务使用者配置的旧版本:

<dubbo:reference id="barService" interface="com.foo.BarService" version="1.0.0" />

  5.4 新版本的服务使用者配置:

<dubbo:reference id="barService" interface="com.foo.BarService" version="2.0.0" />

  5.5 如果不需要区分版本,可以按以下方式配置:

<dubbo:reference id="barService" interface="com.foo.BarService" version="*" />

 

六、本地存根

  当使用RPC时,客户端通常只使用接口,但有时客户端也希望在客户机中执行部分逻辑。例如:执行ThreadLocalcache,验证参数,在调用失败时返回模拟数据,等等。

  为了解决这个问题,您可以在api中配置存根,以便当客户端生成代理实例时,它将代理传递给Stub通过构造函数,然后可以在存根实现代码中实现您的逻辑。

  

 

   6.1 在Spring配置文件中配置如下:

<dubbo:service interface="com.foo.BarService" stub="true" />

    或

<dubbo:service interface="com.foo.BarService" stub="com.foo.BarServiceStub" />

  6.2 提供Stub实现

package com.foo;
public class BarServiceStub implements BarService {
    private final BarService barService;

    // The real remote proxy object is passed in through the constructor
    public BarServiceStub(BarService barService){
        this.barService = barService;
    }

    public String sayHello(String name) {
        // The following code is executed on the client. You can do local ThreadLocal caching on the client side, or verify parameters, etc.
        try {
            return barService.sayHello(name);
        } catch (Exception e) {
            // You can return the mock data.
            return "MockData";
        }
    }
}
  1. Stub必须有一个可以传递代理的构造函数。

  2. BarServiceStub实现BarService,它有一个在远程BarService实例中传递的构造函数

 

Guess you like

Origin www.cnblogs.com/xiao-ran/p/12013677.html