dubbo 的使用

添加dubbo的jar包

安装中间件zookeeper

1,	传入centos中
2,	解压  tar zxf zookeeper-3.4.6.tar.gz
3,	切换目录   cd zookeeper-3.4.6
4,	新建文件夹  mkdir data
5,	切换目录  cd conf 
6,	给zoo_sample.cfg重命名   mv zoo_sample.cfg  zoo.cfg
7,	编辑zoo.cfg    vim zoo.cfg
8,	把dataDir=/tmp/zookeeper修改为刚刚data路径
            使用delete删除,
            a在当前位置之后插入/root/zookeeper-3.4.6/data
            退出编辑 按esc  输入:wq
9,      返回上一级目录 cd ..  进入bin目录  cd bin
10,     开启服务./zkServer.sh start  
            检查是否开启成功./zkServer.sh status 
            JMX enabled by default
            Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
            Mode: standalone
            关闭服务./zkServer.sh stop

在服务层spring的配置文件中添加dubbo的约束,发布服务:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
	
	<!-- 配置包扫描器,扫描所有带@Service注解的类 -->
	<context:component-scan base-package="com.taotao.service"/>
	
	<!-- 发布dubbo服务 -->
	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="taotao-manager" />
	<!-- 注册中心的地址 -->
	<dubbo:registry protocol="zookeeper" address="192.168.10.129:2181" />
	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880" />
	<!-- 声明需要暴露的服务接口 -->
	<dubbo:service interface="com.taotao.service.ItemService" ref="itemServiceImpl" timeout="300000"/>
	
</beans>

在表现层spring的配置文件中添加约束,引用服务:

<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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">

	<!-- 配置注解驱动 -->
	<mvc:annotation-driven />
	<!-- 视图解析器 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
	</bean>
	
	<!-- 资源映射 -->
	<mvc:resources location="/css/" mapping="/css/**"></mvc:resources>
	<mvc:resources location="/js/" mapping="/js/**"></mvc:resources>
	<!-- 配置包扫描器,扫描@Controller注解的类 -->
	<context:component-scan base-package="com.taotao.controller" />
	<!-- 配置资源映射 -->
	<mvc:resources location="/css/" mapping="/css/**" />
	<mvc:resources location="/js/" mapping="/js/**" />
	<!-- 引用dubbo服务 -->
	<dubbo:application name="taotao-manager-web" />
	<dubbo:registry protocol="zookeeper" address="192.168.10.129:2181" />
	<dubbo:reference interface="com.taotao.service.ItemService"
		id="itemService" />
		
</beans>      

dobbo的监控中心使用方法:

1,	安装tomcat
2,	tar zxf apache-tomcat-7.0.90.tar.gz  解压tomcat
3,	把war包传入centos
4,	cp dubbo-admin-2.5.4.war apache-tomcat-7.0.90/webapps/dubbo-admin.war
            复制重命名war包到webapps
5,     [root@freeit apache-tomcat-7.0.90]# bin/startup.sh 
6,     [root@freeit apache-tomcat-7.0.90]# tail -f logs/catalina.out
7,      访问http://192.168.10.129:8080/dubbo-admin/用户名:root,密码:root

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值