Apache CXF负载平衡和故障转移
最终,我们最终获得了自己开发的负载平衡微库(ESB / UDDI / WS-Addressing似乎是一个有趣的替代方案,但在我们的情况下这是一个过大的选择)。 如果我们只知道Apache CXF已经(几乎)开箱即用地支持所有这些功能?
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:jaxws="http://cxf.apache.org/jaxws"xmlns:clustering="http://cxf.apache.org/clustering"xmlns:util="http://www.springframework.org/schema/util"><jaxws:client id="testServiceClient"serviceClass="com.blogspot.nurkiewicz.cxfcluster.SimpleService"address="http://serverA/simple"></jaxws:client></beans>
<jaxws:client id="testServiceClient"serviceClass="com.blogspot.nurkiewicz.cxfcluster.SimpleService"address="http://serverA/simple"><jaxws:features><clustering:failover><clustering:strategy><bean class="org.apache.cxf.clustering.RandomStrategy"><property name="alternateAddresses"><util:list><value>http://serverB/simple</value><value>http://serverC/simple</value><value>http://serverD/simple</value></util:list></property></bean></clustering:strategy></clustering:failover></jaxws:features></jaxws:client>
<cxf:bus><cxf:features><cxf:logging/></cxf:features>
</cxf:bus>
<bean id="abstractLoggingInterceptor" abstract="true"><property name="prettyLogging" value="true"/>
</bean>
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" parent="abstractLoggingInterceptor"/>
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" parent="abstractLoggingInterceptor"/><cxf:bus><cxf:inInterceptors><ref bean="loggingInInterceptor"/></cxf:inInterceptors><cxf:outInterceptors><ref bean="loggingOutInterceptor"/></cxf:outInterceptors><cxf:outFaultInterceptors><ref bean="loggingOutInterceptor"/></cxf:outFaultInterceptors><cxf:inFaultInterceptors><ref bean="loggingInInterceptor"/></cxf:inFaultInterceptors>
</cxf:bus>
<jaxws:client id="testServiceClient" serviceClass="com.blogspot.nurkiewicz.cxfcluster.SimpleService"><jaxws:features><clustering:loadDistributor><clustering:strategy><bean class="org.apache.cxf.clustering.SequentialStrategy"><property name="alternateAddresses"><util:list><value>http://serverA/simple</value><value>http://serverB/simple</value><value>http://serverC/simple</value><value>http://serverD/simple</value></util:list></property></bean></clustering:strategy></clustering:loadDistributor></jaxws:features></jaxws:client>
<jaxws:client id="testServiceClient" serviceClass="com.blogspot.nurkiewicz.cxfcluster.SimpleService"><jaxws:features><clustering:loadDistributor><clustering:strategy><bean class="org.apache.cxf.clustering.SequentialStrategy"><property name="alternateAddresses" ref="alternateAddresses"/></bean></clustering:strategy></clustering:loadDistributor></jaxws:features></jaxws:client><util:list id="alternateAddresses" list-class="java.util.concurrent.CopyOnWriteArrayList"><value>http://serverA/simple</value><value>http://serverB/simple</value><value>http://serverC/simple</value><value>http://serverD/simple</value>
</util:list>
@Service
@ManagedResource
public class AlternateAddressesManager {@Resourceprivate List alternateAddresses;@ManagedOperationpublic void addAlternateAddress(String address) {alternateAddresses.add(address);}@ManagedOperationpublic boolean removeAlternateAddress(String address) {return alternateAddresses.remove(address);}@ManagedAttributepublic List getAlternateAddresses() {return Collections.unmodifiableList(alternateAddresses);}}
<bean id="testServiceClientFactoryBean" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"><property name="serviceClass" value="com.blogspot.nurkiewicz.cxfcluster.SimpleService"/><property name="features"><util:list><bean class="org.apache.cxf.clustering.LoadDistributorFeature"><property name="strategy"><bean class="org.apache.cxf.clustering.SequentialStrategy"><property name="alternateAddresses" ref="alternateAddresses"/></bean></property></bean></util:list></property>
</bean><bean id="testServiceClientTarget" factory-bean="testServiceClientFactoryBean" factory-method="create" scope="prototype" lazy-init="true"/><bean id="testServiceClient" class="org.springframework.aop.framework.ProxyFactoryBean"><property name="targetSource"><bean class="org.springframework.aop.target.CommonsPoolTargetSource"><property name="targetClass" value="com.blogspot.nurkiewicz.cxfcluster.SimpleService"/><property name="targetBeanName" value="testServiceClientTarget"/><property name="maxSize" value="10"/><property name="maxWait" value="5000"/></bean></property>
</bean>
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolUtils;
import org.springframework.aop.target.CommonsPoolTargetSource;public class SynchCommonsPoolTargetSource extends CommonsPoolTargetSource {@Overrideprotected ObjectPool createObjectPool() {return PoolUtils.synchronizedPool(super.createObjectPool());}}
参考: NoBlogDefFound博客上的 JCG合作伙伴 Tomasz 在Apache CXF中启用负载平衡和故障转移 。
- 带有Spring和Maven教程的JAX–WS
- Spring3 RESTful Web服务
- Tomcat 7上具有RESTeasy JAX-RS的RESTful Web服务-Eclipse和Maven项目
翻译自: https://www.javacodegeeks.com/2011/06/apache-cxf-load-balancing-failover.html
Apache CXF负载平衡和故障转移相关推荐
- apache cxf_Apache CXF负载平衡和故障转移
apache cxf 不久前,我们已经面临了基于Apache CXF的负载平衡Web服务客户端的需求. 此外,当某些服务器关闭时,客户端应自动进行故障转移. 更糟糕的是,服务器目标地址列表要从外部服务 ...
- linux 双网卡绑定(bonding)实现负载均衡或故障转移
linux 双网卡绑定(bonding)实现负载均衡或故障转移 我们在这介绍的Linux双网卡绑定实现就是使用两块网卡虚拟成为一块网卡,这个聚合起来的设备看起来是一个单独的以太网接口设备,通俗点讲就是 ...
- 负载均衡和故障转移的使用案例
负载均衡和故障转移 文章目录 1)需求 2)需求分析 3)前期准备 4)配置文件 5)启动相关命令 6)检验 7)补充 1)需求 使用 Flume1 监控一个端口,其 sink 组中的 sink ...
- 高并发应用场景下的负载均衡与故障转移实践,AgileEAS.NET SOA 负载均衡介绍与实践...
一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...
- oracle查询报错clb,Oracle RAC 负载均衡与故障转移(三)
Server Service TAF https://www.cndba.cn/Breath/article/2324 服务端 service TAF 1.服务器端透明故障转移,通过配置service ...
- was连接oracle rac集群,Oracle 学习之RAC(九) 集群负载均衡及故障转移
查看监听,使用grid用户 11grac1:11grac1-> lsnrctl status LSNRCTL for Linux: Version 11.2.0.3.0 - Production ...
- 故障转移集群仲裁盘_MongoDB负载均衡、故障转移及海量数据应对方案
概述 下面是mongo的三种集群实施方案 主从复制 主节点对外提供读写服务,从节点定期轮询主节点获取读写操作,并在自己的数据副本执行,保持和主节点的一致性,并对外提供读服务. 优点:有一定负载均衡能力 ...
- apache-cxf 使用_使用Apache CXF进行Web服务学习
apache-cxf 使用 在我的最后几个项目中,我使用了Web服务,在某些地方创建它们并在其他地方使用它们. 我认为标准任务(例如创建客户端,创建Web服务等)非常简单,如果遇到问题,有足够的资源. ...
- 使用Apache CXF进行Web服务学习
在我的最后几个项目中,我使用了Web服务,在某些地方创建它们并在其他地方使用它们. 我觉得创建客户端,创建Web服务等标准任务非常简单,如果遇到问题,有足够的资源. 但是对于Web服务,这是一项琐碎的 ...
最新文章
- servlet工作原理_Servlet 生命周期、工作原理
- Delphi中文件名函数-路径、名称、子目录、驱动器、扩展名
- xshell登录VMware虚拟机的初始设置
- python 画三维函数图-Python画三维图-----插值平滑数据
- Ubuntu18.04安装百度网盘
- 引物的设计及修饰最全教程
- 类加载器-双亲委派-源码分析2
- when is completed field filled in the backend
- pygame里面物体闪烁运动_利用自闪烁发光二极管探究小车在倾斜轨道上的运动规律...
- python 水仙花_python 水仙花
- Python画等高线以及标注
- Asp.net Request方法获取客户端的信息
- 谷歌浏览器安装Postman插件 亲测有效!!!
- Windows XP 下安装Perl cpan模块
- windos读写ext3工具_Windows读写Ext3文件系统
- linux桌面监控软件,Ubuntu安装Conky系统监控桌面插件
- 支付宝支付验证签名失败
- 都说DBA 是越老越值钱, 那你是没干过DBA
- pandas爬虫爬取网页表格
- 节点表征学习与节点预测和边预测
热门文章
- 海域动态监视监测管理系统_监视和管理备份系统
- jpa执行sql脚本_JPA persistence.xml SQL脚本定义
- lombok 简化代码_如何编写更少,更好的代码,或Project Lombok
- 琥珀ai_琥珀项目:Java的未来暴露
- twitter自定义api_为Twitter4j创建自定义SpringBoot Starter
- 哈希策略_优化哈希策略的简介
- ginkgo spi 错误_开发SPI时不要犯这个错误
- orm java_Java 8 Friday:不再需要ORM
- JAX-RS和OpenAPI对Hypermedia API的支持:任重而道远
- q7goodies事例_Java 8 Friday Goodies:java.io终于成功了!