soa cxf解决方案中的代理模式

背景

通过cxf实现SOA间的远程方法调用,项目结构如下图所示:

soa cxf解决方案中的代理模式

 

  • Site通过cxf调用Service
  • Site、Service依赖Commons包

服务间使用代理模式,可以方便替换RPC框架。且面向接口编程方便切换接口注入。

代理实现

以账户(Account)实现为例。AccountServiceRemoteImpl为代理类,代理AccountServiceImpl实现。UML类图如下所示:

soa cxf解决方案中的代理模式

包结构

AccountServiceAgent、IAccountService、IAccountWebService、AccountServiceRemoteImpl、AccountServiceRemoteImplWithCache在Commons包中。

AccountServiceImpl、AccountWebServiceImpl在具体的服务中。

类作用

  • AccountServiceAgent:对外提供服务
  • IAccountService:账户服务接口
  • AccountServiceRemoteImpl:将webservice调用的string反序列为java对象
  • AccountServiceRemoteImplWithCache:缓存service的成功响应结果
  • AccountServiceImpl:账户服务实现
  • IAccountWebService:账户服务webservice接口
  • AccountWebServiceImpl:将账户服务实现返回的结果转换为string类型

在site中,IAccountService的注入实现为AccountServiceRemoteImpl,需要通过cxf远程调用服务中的实现,如果有service层的缓存,注入实现为AccountServiceRemoteImplWithCache。在service中,IAccountService的注入实现为AccountServiceImpl。