通过dubbo暴露接口调用方法,及基于zookeeper的dubbo涉及配置文件

现在很流行的Dubbo很多朋友都听说过吧,最近我也在看这方面的东西,分享先我的心得笔记。

先说说我们团队要做的项目框架,很简单重在实现基于zookeeper的dubbo注册。

框架:springmvc+spring+mybatis+shiro+zookeeper+dubbo

项目分三层,model存放数据,view页面展示、controller下面具体逻辑实现。通过dubbo消费方和供应方注册,供应方给消费方暴露接口,供消费方调用。 
工程部署需要配置文件有: 


spring-provider-dubbo.xml(提供方配置文件)

[plain]  view plain  copy
 print ?
  1.   
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  4.   xsi:schemaLocation="http://www.springframework.org/schema/beans  
  5.     http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.     http://code.alibabatech.com/schema/dubbo   
  7.     http://code.alibabatech.com/schema/dubbo/dubbo.xsd  
  8.     ">   
  9.     
  10.     
  11.     
  12.     
  13.     
  14.     
  15.     
  16.     
  17.     
  18.      
  19.   

spring-consumer-dubbo.xml(消费方配置文件)
{-- 
<-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 --> 

<-- 使用zookeeper注册中心暴露服务地址 --> 

<-- 生成远程服务代理,可以像使用本地bean一样使用demoService --> 
 
--} 

例如我的配置:

[plain]  view plain  copy
 print ?
  1.   
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.   xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  4.   xsi:schemaLocation="http://www.springframework.org/schema/beans  
  5.     http://www.springframework.org/schema/beans/spring-beans.xsd  
  6.     http://code.alibabatech.com/schema/dubbo   
  7.     http://code.alibabatech.com/schema/dubbo/dubbo.xsd  
  8.     ">   
  9.      
  10.      
  11.       
  12.        
  13.   

dubbo.properties 
{-- 
<--基于ZooKeeper的Dubbo注册中心直接部署tomcat,修改WEB-INF下文件--> 
dubbo.registry.address=zookeeper://127.0.0.1:2181 
dubbo.admin.root.password=root 
dubbo.admin.guest.password=guest 
--} 

本人的配置如下:

[plain]  view plain  copy
 print ?
  1. dubbo.registry.address=zookeeper://127.0.0.1:2181  
  2. dubbo.admin.root.password=root  
  3. dubbo.admin.guest.password=guest  

zoo_sample.cfg 
{-- 
zookeeper/conf/下,修改zoo_sample.cfg为zoo.cfg,启动bin/下zkServer.cmd 
--}

本人的配置如下:

[plain]  view plain  copy
 print ?
  1. # The number of milliseconds of each tick  
  2. tickTime=2000  
  3. # The number of ticks that the initial   
  4. # synchronization phase can take  
  5. initLimit=10  
  6. # The number of ticks that can pass between   
  7. # sending a request and getting an acknowledgement  
  8. syncLimit=5  
  9. # the directory where the snapshot is stored.  
  10. # do not use /tmp for storage, /tmp here is just   
  11. # example sakes.  
  12. dataDir=D:\\Java\\zookeeper-3.4.5\\data  
  13. dataLogDir=D:\\Java\\zookeeper-3.4.5\\log  
  14. # the port at which the clients will connect  
  15. clientPort=2181  
  16. #  
  17. # Be sure to read the maintenance section of the   
  18. # administrator guide before turning on autopurge.  
  19. #  
  20. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
  21. #  
  22. # The number of snapshots to retain in dataDir  
  23. # autopurge.snapRetainCount=3  
  24. # Purge task interval in hours  
  25. # Set to "0" to disable auto purge feature  
  26. # autopurge.purgeInterval=1  

因为引入dubbo,摒弃了原有Web Service项目的wdls暴露,由于项目依赖关系严重,项目使用maven构建,通过Maven pom.xml三维坐标引入jar包,调用dubbo暴露接口开发。

你可能感兴趣的:(dubbo)