参考官方的部署指南:github.com/ctripcorp/a…html
由于个人Apollo是部署在阿里云上的,因此在本地测试的时候须要指定JVM参数
-Dapollo.configService=http://config-service的公网IP:端口
来跳过meta service的服务发现。java
application.properties
中配置要链接的appId
git
app.id = 100001
复制代码
指定当前Apollo客户端的Meta Server地址github
建议经过在server.properties
配置文件中指定apollo.meta=http://config-service-url
,使Meta Server和应用解耦。redis
/opt/settings/server.properties
C:\opt\settings\server.properties
官方推荐对Meta Server作负载均衡。apache
对于服务端和消费端公用的配置配置(全局配置)到Apollo一个公共的NameSpace
中,缺省的名称为dubbo。bootstrap
在dubbo
中建立一个dubbo.properties
的key,value就是咱们的配置内容。例如bash
dubbo.consumer.check=false
dubbo.registry.address = zookeeper://localhost:2181
dubbo.registry.check = false
dubbo.registry.simplified = true ## 简化注册中心url
dubbo.protocol.name = dubbo
dubbo.protocol.port = 20880
dubbo.protocol.dispatcher = message ## 消息派发策略
## 元数据中心
dubbo.metadata-report.address = redis://localhost:6379
dubbo.metadata-report.retry-times = 30
dubbo.metadata-report.retry-period = 5000
dubbo.metadata-report.cycle-report = false
复制代码
在application
中配置应用级别的配置app
在SpringBoot自己的appilcation.properties
中配置:负载均衡
app.id = 100001
# 可选
apollo.meta=http://config-service-url
# 开启apollo名空间的自动注入,缺省注入application
apollo.bootstrap.enabled = true
# 若是要引入其余的namespaces 则配置
# apollo.bootstrap.namespaces = application,javaConfig
# dubbo 配置中心地址
dubbo.config-center.address= apollo://39.106.170.184:8080
# dubbo namespace 缺省为dubbo
dubbo.config-center.namespaces = dubbo
# 配置中心的配置覆盖本地配置
dubbo.config-center.highest-priority = false
# 全局级配置文件所映射到的key
# zookeeper - 默认路径/dubbo/config/dubbo/dubbo.properties
# apollo - dubbo namespace中的dubbo.properties键
dubbo.config-center.config-file = dubbo.properties
复制代码
参考文章: