使用dubbo将工程改造成SOA架构

来源:互联网 发布:软件外包行业分析 编辑:程序博客网 时间:2024/06/15 19:35

简述:.有两个服务,一个是web,一个是service,按道理说web是要调用service服务的,但是如果有几十个web,几十个service就会混乱,谁调用谁会出现问题的,所以使用dubbo来解决这个问题

1.使用dubbo需要在linux下布置一个注册中心,使用Zookeeper(1>可以作为集群的管理工具使用。2>可以集中管理配置文件)

 简单布置步骤:

第一步:安装jdk

第二步:把zookeeper的压缩包上传到linux系统。

第三步:解压缩压缩包

tar -zxvf zookeeper-3.4.6.tar.gz

第四步:进入zookeeper-3.4.6目录,创建data文件夹。

第五步:把zoo_sample.cfg改名为zoo.cfg

[root@localhost conf]# mv zoo_sample.cfg zoo.cfg

第六步:修改data属性:dataDir=/root/zookeeper-3.4.6/data

第七步:启动zookeeper

[root@localhost bin]# ./zkServer.sh start

关闭:[root@localhost bin]# ./zkServer.sh stop

查看状态:[root@localhost bin]# ./zkServer.sh status

 注意:需要关闭防火墙。

service iptables stop

永久关闭修改配置开机不启动防火墙:

chkconfig iptables off

如果不能成功启动zookeeper,需要删除data目录下的zookeeper_server.pid文件。

2.在service服务里做下面配置(pojo需要序列化 implements Serializable)

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    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">
      
 <!-- 和service相关的配置 -->
 <context:component-scan base-package="com.dd.service">
 </context:component-scan>
 <!-- dubbos使用zookeeper发布服务 -->
<!--  指明服务所在的工程 -->
 <dubbo:application name="dd-manager"/>
      <!-- 指明注册中心 -->  
      <dubbo:registry protocol="zookeeper" address="10.0.143.145:2181"></dubbo:registry>
      <!-- 把服务暴露出去65521 -->
      <dubbo:protocol name="dubbo" port="65521"></dubbo:protocol>
      <!-- 指明服务接口,指明服务实例-->
      <dubbo:service interface="com.dd.service.ItemService" ref="itemServiceImpl" timeout="600000"></dubbo:service>
</beans>        

3.在web服务里做下面配置(pojo需要序列化implements Serializable)

<?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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    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://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-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">
      
 <!-- 和controller相关的配置 -->
 <context:component-scan base-package="com.dd.controller"></context:component-scan>
 
 <!-- 处理器映射器,处理器适配器 -->  
 <mvc:annotation-driven></mvc:annotation-driven>  
 
 <!-- 视图解析器 -->
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix" value="/WEB-INF/jsp/"></property>
       <property name="suffix" value=".jsp"></property>
 </bean>
 
 <!-- 资源映射  -->
 <mvc:resources location="/WEB-INF/css/" mapping="/css/**"></mvc:resources>
 <mvc:resources location="/WEB-INF/js/" mapping="/js/**"></mvc:resources>
 
 
 
 <!-- 调用服务 -->
 <!-- 指明所在的工程 -->
 <dubbo:application name="dd-manager-web"/>
 <!-- 指明注册中心 -->
 <dubbo:registry protocol="zookeeper" address="10.0.143.145:2181" ></dubbo:registry>
 <dubbo:reference interface="com.dd.service.ItemService" id="itemservice"></dubbo:reference>
 
</beans>        









 
 
 
      


















原创粉丝点击