背景
通过cxf实现SOA间的远程方法调用,项目结构如下图所示:
- Site通过cxf调用Service
- Site、Service依赖Commons包
服务间使用代理模式,可以方便替换RPC框架。且面向接口编程方便切换接口注入。
代理实现
以账户(Account)实现为例。AccountServiceRemoteImpl为代理类,代理AccountServiceImpl实现。UML类图如下所示:
包结构
(类图绿色部分)AccountServiceAgent、IAccountService、IAccountWebService、AccountServiceRemoteImpl、AccountServiceRemoteImplWithCache在Commons包中。
(类图蓝色部分)AccountServiceImpl、AccountWebServiceImpl在具体的服务中。
类作用
- AccountServiceAgent:对外提供服务
- IAccountService:账户服务接口
- AccountServiceRemoteImpl:AccountServiceImpl的远程代理类,将响应的内容反序列化为Java对象。(本项目将json格式的String反序列化为Java对象)
- AccountServiceRemoteImplWithCache:缓存service的成功响应结果
- AccountServiceImpl:账户服务实现,真正的业务逻辑实现类
- IAccountWebService:账户服务webservice接口
- AccountWebServiceImpl:webservice接口实现类,AccountServiceImpl的本地代理类,将Java对象序列化进行响应。(本项目将Java对象序列化为j'son格式的String)
在site中,IAccountService的注入实现为AccountServiceRemoteImpl,需要通过cxf远程调用服务中的实现,如果有service层的缓存,注入实现为AccountServiceRemoteImplWithCache。在service中,IAccountService的注入实现为AccountServiceImpl。