dubbo 试用全过程

概述:

dubbo服务容器是一个standalone的启动程序,因为后台服务不需要Tomcat或JBoss等Web容器的功能,如果硬要用Web容器去加载服务提供方,增加复杂性,也浪费资源。 服务容器只是一个简单的Main方法,并加载一个简单的Spring容器,用于暴露服务。 服务容器的加载内容可以扩展,内置了spring, jetty, log4j等加载,可通过Container扩展点进行扩展,参见:Container Spring Container 自动加载META-INF/spring目录下的所有Spring配置

1.下载地址

https://github.com/alibaba/dubbo/

2.导入IDE

cd ~/dubbo
mvn eclipse:eclipse(执行了两次mvn下载,第一次执行失败有些jar没下载下来,重新执行成功)

Eclipse -> Menu -> File -> Import -> Exsiting Projects to Workspace -> Browse -> Finish

3. 如果修改dubbo源码则需要重新构建dubbo
cd ~/dubbo
mvn clean install -Dmaven.test.skip
cd dubbo/target

4.Install the zookeeper registry:
cd ~
wget http://www.apache.org/dist//zookeeper/zookeeper-3.3.3/zookeeper-3.3.3.tar.gz
tar zxvf zookeeper-3.3.3.tar.gz
cd zookeeper-3.3.3/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
- edit: dataDir=/home/xxx/data
cd ../bin
./zkServer.sh start
cd ~/dubbo/dubbo-demo-provider/conf
vi dubbo.properties
- edit: dubbo.registry.adddress=zookeeper://127.0.0.1:2181
cd ../bin
./restart.sh
cd ~/dubbo/dubbo-demo-consumer/conf
vi dubbo.properties
- edit: dubbo.registry.adddress=zookeeper://127.0.0.1:2181
cd ../bin
./restart.sh
cd ~/dubbo/dubbo-simple-monitor/conf
vi dubbo.properties
- edit: dubbo.registry.adddress=zookeeper://127.0.0.1:2181
cd ../bin
./restart.sh

5.启动过程
00zkServer.cmd
01start_provider.bat
02start_consumer.bat(可选,基本不用)
03start_monitor.bat (可选,监控使用,会占用本地8080端口)
04start_admin.bat(基本不用,管理控制器部署在tomcat下即可,dubbo-admin-2.5.4-SNAPSHOT.war)

6.服务端开发
通过dubbo自带例子下进行开发,采用maven构建,mvn build

7.客户端开发
通过java工程开发,但是至少需要导入如下jar


8.管理控制台
http://127.0.0.1:8087(8080端口被监控应用占用了,找了好长时间的原因)
dubbo-admin-2.5.4-SNAPSHOT.war(该war一定要部署在tomcat/webapp/ROOT下面)

root/rooot
消费者访问服务必须长连接才能在管理控制台看见消费者,因为是基于zookeeper进行连接的,一但客户端线程结束,则立马会断开zookeeper的连接
9.客户端事例代码
 1 package com.rigid;
 2 
 3 import java.io.IOException;
 4 
 5 import org.springframework.context.support.FileSystemXmlApplicationContext;
 6 
 7 import com.alibaba.dubbo.demo.VendorService;
 8 
 9 public class Main3 {
10 
11     /**
12      * @param args
13      * @throws IOException 
14      */
15     public static void main(String[] args) throws IOException {
16         FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
17                 "/bin/conf/spring.*");
18         
19         context.start();
20 
21         VendorService vendorService = (VendorService) context.getBean("vendorService");
22 
23         vendorService.createVendor("rigid");
24         
25         System.in.read();  
26 
27     }
28 
29 }
View Code
1 <?xml version="1.0" encoding="UTF-8"?>
2 
3 <beans xmlns="http://www.springframework.org/schema/beans"
4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
5     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6     
7     <bean id="orderService" class="com.rigid.OrderService"></bean>    
8     
9 </beans>
View Code

 


posted on 2016-08-16 22:33  rigidwang  阅读(325)  评论(0编辑  收藏  举报