转:http://blog.csdn.net/u011270461/article/details/12144623
建议参考资料:
http://blog.csdn.net/lin_fs/article/details/7395307
http://blog.csdn.net/goliathray/article/details/8565801
http://zy116494718.iteye.com/blog/1830138
http://agapple.iteye.com/blog/1292473
http://www.open-open.com/news/view/1442a5c
http://code.alibabatech.com/wiki/display/dubbo/Home
http://code.alibabatech.com/wiki/display/dubbo/User+Guide-zh
先把zookeeper在本地给安装好,
安装方法参考:http://blog.csdn.net/wxwzy738/article/details/16330253
这里的话讲述了两个工程一个工程是提供服务的,一个工程是调用服务的,因为dubbo是跟spring进行无缝连接的,故功能配置在spring的配置文件中,跟spring进行整合开发
1、工程是以maven进行构建的,使用的jar包如下:

Maven 提供包
发布版和快照版要同时有才能在另的项目中运用。
假如一个项目 为
4.0.0
cn.com.abel
springProject
war
0.0.1-SNAPSHOT
springProject Maven Webapp
http://maven.apache.org
先mvn intsall后 mvn deploy 上传到服务器
4.0.0
cn.com.abel
springProject
war
0.0.1
springProject Maven Webapp
http://maven.apache.org
先mvn intsall后 mvn deploy 上传到服务器后在别在项目中用
cn.com.abel
springProject
0.0.1
com.alibaba
dubbo
2.3.5
org.apache.hadoop
zookeeper
3.3.0
com.101tec
zkclient
0.4
org.apache.zookeeper
zookeeper
org.jboss.netty
netty
3.2.5.Final
org.springframework
spring-core
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-asm
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-aspects
${spring.version}
javassist
javassist
3.3
javassist 包要1.5GA以上,不然会报错
com.zlh 包下的接口文件要先于xml文件之前
2、服务提供者的工程
a、dubbo-demo-api 定义接口
- public interface IProcessData {
- public String deal(String data);
- }
b、dubbo-demo-provider 服务提供者
- public class ProcessDataImpl implements IProcessData {
-
-
-
-
- @Override
- public String deal(String data) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return "Finished:" + data;
- }
- }
c、applicationProvider.xml配置
- 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:application name="hello-world-app" />
-
-
- <dubbo:registry address="zookeeper://127.0.0.1:2181" />
-
-
-
- <dubbo:service interface="com.huangjie.dubbo_Service.service.IProcessData"
- ref="demoService" executes="10" />
-
-
-
-
-
- <bean id="demoService" class="com.huangjie.dubbo_Service.service.impl.ProcessDataImpl" />
-
- beans>
d、启动服务
- public class DubboProviderMain {
- public static void main(String[] args) throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
- new String[]{"applicationProvider.xml"});
- context.start();
-
- System.out.println("Press any key to exit.");
- System.in.read();
- }
- }
3、服务调用者的工程
a、调用类
- public class ConsumerThd implements Runnable {
-
-
-
-
- @Override
- public void run() {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
- new String[]{"applicationConsumer.xml"});
- context.start();
-
- IProcessData demoService = (IProcessData) context.getBean("demoService");
-
-
-
- String hello = demoService.deal("nihao");
-
- System.out.println(Thread.currentThread().getName() + " "+hello);
- }
-
- public static void main(String[] args) {
- new Thread(new ConsumerThd()).start();
-
-
-
-
- }
- }
b、applicationConsumer.xml配置
- 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:application name="consumer-of-helloworld-app" />
-
-
- <dubbo:registry address="zookeeper://127.0.0.1:2181" />
- <dubbo:consumer timeout="5000"/>
-
- <dubbo:reference id="demoService" interface="com.huangjie.dubbo_Service.service.IProcessData" />
- beans>
4、最后需要把zookeeper的服务给启动,在zookeeper安装文件夹下面的bin目录里面的zkServer.cmd给点击运行。不要关闭窗口,保持服务运行

这样整个调用就完成了,这样的好处是只要远程提供ip地址及端口号,以及对外调用的类,客户端就可以调用,客户端不必知道服务端的地址之类的
而且服务端可以开多个zookeeper服务,这样如果其中一个zookeeper 服务死掉了,其他服务还能正常运行
dubbo管理控制台安装
分类: 分布式服务
2013-06-20 21:48 1142人阅读 收藏 举报
dubbo管理控制台开源部分主要包含:路由规则,动态配置,服务降级,访问控制,权重调整,负载均衡,等管理功能。
1、下载dubbo
地址:http://code.alibabatech.com/mvn/releases/com/alibaba/dubbo-admin/2.4.1/dubbo-admin-2.4.1.war
本人将tomcat安装在/opt/目录下,先删除tomcat/webapps下自带的ROOT文件夹,将下载的war包解压到webapps/ROOT,命令如下:
- unzip dubbo-admin-2.4.1.war -d /opt/apache-tomcat-6.0.37/webapps/ROOT
配置:
(或将dubbo.properties放在当前用户目录下)
- vim webapps/ROOT/WEB-INF/dubbo.properties
配置信息如下:
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
这边使用的是zookeeper的注册中心。
启动
说明:这边启动tomcat之前必须先启动zookeeper的。
- ./bin/catalina.sh run
-
- Ctrl + C 停止tomcat
出现以下界面说明安装配置成功,登录密码为root/root

登录成功界面:
