分布式架构学习之:001--使用Dubbo对传统工程进行服务化改造
2017-05-09 17:15
766 查看
样例工程:传统的单工程项目(edu-demo)
Maven
J-UI
Struts2
Spring3
MyBatis3
Druid
MySQL5.6
只有一个用户信息表(增、删除、查、改)
Action中注入业务逻辑的类
业务逻辑类中使用dao
服务化的思想是将业务层service和dao层抽象出来,单独形成可以运行的工程,供上层应用调用。
改造成Dubbo服务调用方式后的工程结构
edu-common-parent(Maven父配置):是所有工程的公共部分
edu-facade-user(用户服务接口):是服务提供最和消费者的通信契约--接口,其实可以不需要这个工程,把这些接口放到实现和消费中,但是使用Maven来管理更好。
edu-service-user(用户服务实现):服务实现
edu-web-boss(服务消费者):服务消费,目前是web工程
部署环境规划
192.168.2.61 edu-web-boss(consumer)
192.168.3.71 zookeeper-3.4.6(注册中心)
192.168.3.72 edu-service-user(provider)
192.168.4.201 MySQL5.6(数据库)
分布式之后,将业务逻辑形成接口,对外公布,放在edu-facade-user中,实现放在edu-service-user,本类中注入业务逻辑类,实现真正的逻辑。Action中就注入公开的接口。
定义接口
接口的实现
在spring-provider.xml中进行服务注册
消费端
在spring-comsumer.xml中进行服务消费配置
Maven
J-UI
Struts2
Spring3
MyBatis3
Druid
MySQL5.6
只有一个用户信息表(增、删除、查、改)
Action中注入业务逻辑的类
@Scope("prototype") public class PmsUserAction extends BaseAction { @Autowired private PmsUserBiz pmsUserBiz;
业务逻辑类中使用dao
@Service("pmsUserBiz") public class PmsUserBiz { @Autowired private PmsUserDao pmsUserDao;
服务化的思想是将业务层service和dao层抽象出来,单独形成可以运行的工程,供上层应用调用。
改造成Dubbo服务调用方式后的工程结构
edu-common-parent(Maven父配置):是所有工程的公共部分
edu-facade-user(用户服务接口):是服务提供最和消费者的通信契约--接口,其实可以不需要这个工程,把这些接口放到实现和消费中,但是使用Maven来管理更好。
edu-service-user(用户服务实现):服务实现
edu-web-boss(服务消费者):服务消费,目前是web工程
部署环境规划
192.168.2.61 edu-web-boss(consumer)
192.168.3.71 zookeeper-3.4.6(注册中心)
192.168.3.72 edu-service-user(provider)
192.168.4.201 MySQL5.6(数据库)
分布式之后,将业务逻辑形成接口,对外公布,放在edu-facade-user中,实现放在edu-service-user,本类中注入业务逻辑类,实现真正的逻辑。Action中就注入公开的接口。
定义接口
接口的实现
@Service("pmsUserFacade") public class PmsUserFacadeImpl implements PmsUserFacade { @Autowired private PmsUserBiz pmsUserBiz;
在spring-provider.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="gw-service-user" /> <!-- 使用zookeeper注册中心暴露服务地址 --> <dubbo:registry protocol="zookeeper" address="192.168.3.71:2181" /> <!-- 用dubbo协议在20880端口暴露服务 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 用户服务接口 --> <dubbo:service interface="wusc.edu.facade.user.service.PmsUserFacade" ref="pmsUserFacade" /> </beans>
消费端
在spring-comsumer.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="edu-web-boss" /> <!-- 使用zookeeper注册中心暴露服务地址 --> <!-- 注册中心地址 --> <dubbo:registry protocol="zookeeper" address="192.168.3.71:2181" /> <!-- 用户服务接口 --> <dubbo:reference interface="wusc.edu.facade.user.service.PmsUserFacade" id="pmsUserFacade" check="false" /> </beans>
相关文章推荐
- 分布式架构学习之:003--使用Dubbo进行规模服务化前的工程结构优化
- dubbo对传统ssm进行服务化改造的思路以及一些分布式工具实现的思路
- 初步了解学习将传统单机应用改造成Dubbo服务的过程
- 使用 Dubbo 对遗留单体系统进行微服务改造
- 基于Dubbo的分布式系统架构-使用Dubbo进行规模服务化前的工程结构优化
- Dubbo : 传统工程改造(二)
- 使用dubbo将工程改造成SOA架构
- DELPHI学习笔记--使用通配符进行模糊查询
- 学习使用AutoMake1.9的自动生成工程文件(一)——网络文章摘要
- Ajax学习摘录之第十部分 使用 JSON 进行数据传输
- 使用MAVEN进行工程自动化构建(1)
- 学习JavaFX Script,第二部分:使用RMI进行远程通信
- 『框架设计(第2版)CLR Via C#』学习笔记——使用is和as操作符来进行强制类型转换
- 转载--Ajax学习---使用 JSON 进行数据传输
- 需求工程系列(六)- 在已有系统改造中如何使用用例技术
- Asp.net学习笔记----使用GridView+ObjectDataSource进行自定义分页排序
- 多线程学习-使用临界区进行线程同步--发布日期:2008-07-17 16:38
- Eclipse学习6-使用CVS进行团队开发(上)
- .NET学习(6) 使用WinForms进行GUI设计
- 如何使用jar命令对java工程进行打包