dubbo服务:RPC 远程过程调用
zookeeper: 注册中心
如果要增加服务,只需要在另一台电脑上打包一份代码启动Bootstrap即可(配置文件包含zookeeper的注册中心的地址)
这样就会把新服务注册到zookeeper
服务端:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
default-lazy-init="false">
<!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->
<dubbo:application name="test_provider"/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry id="test_reg" address="zookeeper://192.168.191.128:2181" check="false" subscribe="false"></dubbo:registry>
<dubbo:protocol name="dubbo" port="20880"/>
<!-- 要暴露的服务接口 -->
<dubbo:service interface="com.zw.service.IUserService" ref="userService" registry="test_reg" />
<context:component-scan base-package="com.zw.service.impl"></context:component-scan>
</beans>
@Service("userService")
public class UserServiceImpl implements IUserService {
private static final Logger LOG = LoggerFactory.getLogger(UserServiceImpl.class);
@Autowired
private UserMapper userMapper;
public List<UserBO> findUsers(UserBO user) {
}}
消费端:
<dubbo:application name="test_consumer"/>
<!-- 使用zookeeper注册中心暴露服务地址 -->
<dubbo:registry id="test_reg" address="zookeeper://192.168.191.128:2181" check="false"></dubbo:registry>
<!-- 要引用的服务 -->
<dubbo:reference id="userService" interface="com.zw.service.IUserService" registry="test_reg" timeout="20000"></dubbo:reference>