W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
以屬性配置的方式來配置你的 Dubbo 應用
Dubbo屬性配置有兩個職責:
一個屬性配置的例子 dubbo-spring-boot-samples
## application.properties
# Spring boot application
spring.application.name=dubbo-externalized-configuration-provider-sample
# Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service
dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service
# Dubbo Application
## The default value of dubbo.application.name is ${spring.application.name}
## dubbo.application.name=${spring.application.name}
# Dubbo Protocol
dubbo.protocol.name=dubbo
dubbo.protocol.port=12345
## Dubbo Registry
dubbo.registry.address=N/A
## service default version
dubbo.provider.version=1.0.0
從Dubbo支持的配置來源說起,默認有6種配置來源:
關于dubbo.properties屬性:
下圖展示了配置覆蓋關系的優(yōu)先級,從上到下優(yōu)先級依次降低:
請參考相關內(nèi)容:屬性覆蓋。
屬性配置處理流程請查看 配置加載流程。
目前Dubbo支持的所有配置都是.properties格式的,包括-D、Externalized Configuration等,.properties中的所有配置項遵循一種path-based的配置格式。
在Spring應用中也可以將屬性配置放到application.yml中,其樹層次結構的方式可讀性更好一些。
# 應用級配置(無id)
dubbo.{config-type}.{config-item}={config-item-value}
# 實例級配置(指定id或name)
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
# 服務接口配置
dubbo.service.{interface-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{config-item}={config-item-value}
# 方法配置
dubbo.service.{interface-name}.{method-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{method-name}.{config-item}={config-item-value}
# 方法argument配置
dubbo.reference.{interface-name}.{method-name}.{argument-index}.{config-item}={config-item-value}
應用級配置的格式為:配置類型單數(shù)前綴,無id/name。
# 應用級配置(無id)
dubbo.{config-type}.{config-item}={config-item-value}
dubbo.application.name=demo-provider
dubbo.application.qos-enable=false
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1
針對某個實例的屬性配置需要指定id或者name,其前綴格式為:配置類型復數(shù)前綴 + id/name。
# 實例級配置(指定id或name)
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
dubbo.registries.unit1.address=zookeeper://127.0.0.1:2181
dubbo.registries.unit2.address=zookeeper://127.0.0.1:2182
dubbo.protocols.dubbo.name=dubbo
dubbo.protocols.dubbo.port=20880
dubbo.protocols.hessian.name=hessian
dubbo.protocols.hessian.port=8089
dubbo.service.org.apache.dubbo.samples.api.DemoService.timeout=5000
dubbo.reference.org.apache.dubbo.samples.api.DemoService.timeout=6000
方法配置格式:
# 方法配置
dubbo.service.{interface-name}.{method-name}.{config-item}={config-item-value}
dubbo.reference.{interface-name}.{method-name}.{config-item}={config-item-value}
# 方法argument配置
dubbo.reference.{interface-name}.{method-name}.{argument-index}.{config-item}={config-item-value}
方法配置示例:
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.timeout=7000
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.oninvoke=notifyService.onInvoke
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.onreturn=notifyService.onReturn
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.onthrow=notifyService.onThrow
dubbo.reference.org.apache.dubbo.samples.api.DemoService.sayHello.0.callback=true
等價于XML配置:
<dubbo:reference interface="org.apache.dubbo.samples.api.DemoService" >
<dubbo:method name="sayHello" timeout="7000" oninvoke="notifyService.onInvoke"
onreturn="notifyService.onReturn" onthrow="notifyService.onThrow">
<dubbo:argument index="0" callback="true" />
</dubbo:method>
</dubbo:reference>
parameters參數(shù)為map對象,支持xxx.parameters=[{key:value},{key:value}]方式進行配置。
dubbo.application.parameters=[{item1:value1},{item2:value2}]
dubbo.reference.org.apache.dubbo.samples.api.DemoService.parameters=[{item3:value3}]
triple協(xié)議采用Http2做底層通信協(xié)議,允許使用者自定義Http2的6個settings參數(shù)
配置格式如下:
# 通知對端header壓縮索引表的上限個數(shù)
dubbo.rpc.tri.header-table-size=4096
# 啟用服務端推送功能
dubbo.rpc.tri.enable-push=false
# 通知對端允許的最大并發(fā)流數(shù)
dubbo.rpc.tri.max-concurrent-streams=2147483647
# 聲明發(fā)送端的窗口大小
dubbo.rpc.tri.initial-window-size=1048576
# 設置幀的最大字節(jié)數(shù)
dubbo.rpc.tri.max-frame-size=32768
# 通知對端header未壓縮的最大字節(jié)數(shù)
dubbo.rpc.tri.max-header-list-size=8192
等價于yml配置:
dubbo:
rpc:
tri:
header-table-size: 4096
enable-push: false
max-concurrent-streams: 2147483647
initial-window-size: 1048576
max-frame-size: 32768
max-header-list-size: 8192
可以將 xml 的 tag 名和屬性名組合起來,用 ‘.’ 分隔。每行一個屬性。
如果在 xml 配置中有超過一個的 tag,那么你可以使用 ‘id’ 進行區(qū)分。如果你不指定id,它將作用于所有 tag。
屬性覆蓋是指用配置的屬性值覆蓋config bean實例的屬性,類似Spring PropertyOverrideConfigurer 的作用。
Property resource configurer that overrides bean property values in an application context definition. It pushes values from a properties file into bean definitions. Configuration lines are expected to be of the following form:beanName.property=value
但與PropertyOverrideConfigurer的不同之處是,Dubbo的屬性覆蓋有多個匹配格式,優(yōu)先級從高到低依次是:
#1. 指定id的實例級配置
dubbo.{config-type}s.{config-id}.{config-item}={config-item-value}
#2. 指定name的實例級配置
dubbo.{config-type}s.{config-name}.{config-item}={config-item-value}
#3. 應用級配置(單數(shù)配置)
dubbo.{config-type}.{config-item}={config-item-value}
屬性覆蓋處理流程:
按照優(yōu)先級從高到低依次查找,如果找到此前綴開頭的屬性,則選定使用這個前綴提取屬性,忽略后面的配置。
復數(shù)配置的命名與普通單詞變復數(shù)的規(guī)則相同:
Config Type | 單數(shù)配置 | 復數(shù)配置 |
---|---|---|
application | dubbo.application.xxx=xxx | dubbo.applications.{id}.xxx=xxx dubbo.applications.{name}.xxx=xxx |
protocol | dubbo.protocol.xxx=xxx | dubbo.protocols.{id}.xxx=xxx dubbo.protocols.{name}.xxx=xxx |
module | dubbo.module.xxx=xxx | dubbo.modules.{id}.xxx=xxx dubbo.modules.{name}.xxx=xxx |
registry | dubbo.registry.xxx=xxx | dubbo.registries.{id}.xxx=xxx |
monitor | dubbo.monitor.xxx=xxx | dubbo.monitors.{id}.xxx=xxx |
config-center | dubbo.config-center.xxx=xxx | dubbo.config-centers.{id}.xxx=xxx |
metadata-report | dubbo.metadata-report.xxx=xxx | dubbo.metadata-reports.{id}.xxx=xxx |
ssl | dubbo.ssl.xxx=xxx | dubbo.ssls.{id}.xxx=xxx |
metrics | dubbo.metrics.xxx=xxx | dubbo.metricses.{id}.xxx=xxx |
provider | dubbo.provider.xxx=xxx | dubbo.providers.{id}.xxx=xxx |
consumer | dubbo.consumer.xxx=xxx | dubbo.consumers.{id}.xxx=xxx |
service | dubbo.service.{interfaceName}.xxx=xxx | 無 |
reference | dubbo.reference.{interfaceName}.xxx=xxx | 無 |
method | dubbo.service.{interfaceName}.{methodName}.xxx=xxx dubbo.reference.{interfaceName}.{methodName}.xxx=xxx | 無 |
argument | dubbo.service.{interfaceName}.{methodName}.{arg-index}.xxx=xxx | 無 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: