dubbo注册到 zookeeper + 使用apollo配置中心整合
一、provider (供应者)
pom依赖
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>1.7.0</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-framework</artifactId> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-x-discovery</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> <exclusions> <exclusion> <groupId>slf4j-log4j12</groupId> <artifactId>org.slf4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <exclusions> <exclusion> <groupId>slf4j-log4j12</groupId> <artifactId>org.slf4j</artifactId> </exclusion> </exclusions> </dependency>
本地application.yml配置
app:
id: CFCA-PROVIDER
apollo:
bootstrap:
namespaces: application
enabled: true
eagerLoad:
enabled: true
meta: http://localhost:8080
apollo yml配置(该配置直接配置在了apollo上)
dubbo.application.name = cfca-provider
dubbo.scan.base-packages = com.wlyuan.cfca.application.service
dubbo.registry.address = zookeeper://localhost:2181
dubbo.registry.register = true
dubbo.protocol.name = dubbo
dubbo.protocal.port = 20880
dubbo.register.timeout = 100000
二、consumer (消费者)
pom依赖
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> <exclusions> <exclusion> <groupId>slf4j-log4j12</groupId> <artifactId>org.slf4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <exclusions> <exclusion> <groupId>slf4j-log4j12</groupId> <artifactId>org.slf4j</artifactId> </exclusion> </exclusions> </dependency>
本地application.yml配置
spring:
main:
allow-bean-definition-overriding: true
app:
id: CFCA-CONSUMER
apollo:
bootstrap:
namespaces: application
enabled: true
eagerLoad:
enabled: true
meta: http://localhost:8080
apollo yml 配置
dubbo.application.name = cfca-consumer
dubbo.registry.address = zookeeper://localhost:2181
dubbo.registry.register = true
dubbo.registry.check = false
dubbo.protocol.name = dubbo
dubbo.protocal.port = 20880
dubbo.register.timeout = 100000