dubbo service: RPC remote procedure call
zookeeper: registry
If you want to add a service, you only need to package a code on another computer to start Bootstrap (the configuration file contains the address of the registration center of zookeeper),
which will register the new service with zookeeper
Server:
<?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">
<!-- provider application name information, this is equivalent to a name, our dubbo management page is more clear which application is exposed -->
<dubbo:application name="test_provider"/>
<!-- use zookeeper to register Center exposed service address -->
<dubbo:registry id="test_reg" address="zookeeper://192.168.191.128:2181" check="false" subscribe="false"></dubbo:registry>
<dubbo:protocol name="dubbo" port="20880"/>
<!-- Service interface to be exposed-->
<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) {
}}
Consumer:
<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>