Apache Dubbo:https://cn.dubbo.apache.org/zh-cn/overview/home/
依赖
<!--dubbo-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.3</version>
</dependency>
<!--zookeeper客户端-->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!--zookeeper服务端-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.14</version>
<!--排除日志冲突-->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
服务端
server.port=8081
# 服务的名称
dubbo.application.name=provider
# 注册中心地址
dubbo.registry.address=zookeeper://127.0.0.1:2181
# 扫描包下的服务
dubbo.scan.base-packages=org.example.service
// 服务提供者使用Dubbo的Service注解,注册到注册中心
@org.apache.dubbo.config.annotation.Service
public class ProviderServiceImpl implements ProviderService{}
消费端
# 服务的名称
dubbo.application.name=consumer
# 注册中心地址
dubbo.registry.address=zookeeper://127.0.0.1:2181
// 注册到Spring容器
@Service
public class UserServiceImpl implements UserService{
// 使用dubbo的@Reference注解去注册中心查找服务
@org.apache.dubbo.config.annotation.Reference
private ProviderService providerService;
}