DBUUO相关配置代码介绍

来源:互联网 发布:淘宝开店在哪里拿货 编辑:程序博客网 时间:2024/05/16 04:51


相关代码介绍---生产者

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:dubbo="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans                        http://www.springframework.org/schema/beans/spring-beans.xsd                        http://code.alibabatech.com/schema/dubbo                        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->   <dubbo:application name="dubbo_provider"></dubbo:application>   <!-- 使用zookeeper注册中心暴露服务地址 -->     <dubbo:registry address="zookeeper://127.0.0.1:2181" check="false" subscribe="false" register=""></dubbo:registry>  <!-- 要暴露的服务接口 -->    <dubbo:service interface="com.zooker.RegistryService" ref="testRegistryService" /></beans>

dubbo:registry address="zookeeper://127.0.0.1:2181"表示注册地址;zookeeper在项目启动的时候,将会对连接该地址;
dubbo:service 表示注册的接口内容;其中ref="testRegistryService" 是需要在spring配置文件配置的,依获取对象;
<bean id="testRegistryService" class="com.zooker.impl.RegistryServiceImpl"></bean>spring中注入的内容 ;该对象对了的class是个实体类

消费者

做为消费者,需要知道从何处获取到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-3.1.xsd    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.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-3.1.xsd"    default-lazy-init="false" >   <dubbo:application name="dubbo_consumer"></dubbo:application>   <!-- 使用zookeeper注册中心暴露服务地址 -->     <dubbo:registry address="zookeeper://127.0.0.1:2181" check="false"></dubbo:registry>      <!-- 要引用的服务 -->     <dubbo:reference interface="com.zooker.RegistryService" id="registryService"></dubbo:reference></beans>

dubbo:registry address="zookeeper://127.0.0.1:2181"表示生产者获取接口的地址;
dubbo:reference interface="com.zooker.RegistryService" id="registryService" 从zookeeper中获取的接口对象;

    @Autowired       RegistryService registryService;

在java中只需要将在配置在xml文件中的id对象;即id="registryService"添加到对象当中即可 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:dubbo="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans                        http://www.springframework.org/schema/beans/spring-beans.xsd                        http://code.alibabatech.com/schema/dubbo                        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!-- 提供方应用名称信息,这个相当于起一个名字,我们dubbo管理页面比较清晰是哪个应用暴露出来的 -->   <dubbo:application name="dubbo_provider"></dubbo:application>   <!-- 使用zookeeper注册中心暴露服务地址 -->     <dubbo:registry address="zookeeper://127.0.0.1:2181" check="false" subscribe="false" register=""></dubbo:registry>  <!-- 要暴露的服务接口 -->    <dubbo:service interface="com.zooker.RegistryService" ref="testRegistryService" /></beans>

dubbo:registry address="zookeeper://127.0.0.1:2181"表示注册地址;zookeeper在项目启动的时候,将会对连接该地址;
dubbo:service 表示注册的接口内容;其中ref="testRegistryService" 是需要在spring配置文件配置的,依获取对象;
<bean id="testRegistryService" class="com.zooker.impl.RegistryServiceImpl"></bean>spring中注入的内容 ;该对象对了的class是个实体类

消费者

做为消费者,需要知道从何处获取到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-3.1.xsd    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.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-3.1.xsd"    default-lazy-init="false" >   <dubbo:application name="dubbo_consumer"></dubbo:application>   <!-- 使用zookeeper注册中心暴露服务地址 -->     <dubbo:registry address="zookeeper://127.0.0.1:2181" check="false"></dubbo:registry>      <!-- 要引用的服务 -->     <dubbo:reference interface="com.zooker.RegistryService" id="registryService"></dubbo:reference></beans>

dubbo:registry address="zookeeper://127.0.0.1:2181"表示生产者获取接口的地址;
dubbo:reference interface="com.zooker.RegistryService" id="registryService" 从zookeeper中获取的接口对象;

    @Autowired       RegistryService registryService;

在java中只需要将在配置在xml文件中的id对象;即id="registryService"添加到对象当中即可 zookeeper 会自动的帮助你找的应该实例化的对象;