gpt4 book ai didi

apache - cxf 故障转移恢复

转载 作者:行者123 更新时间:2023-12-03 21:34:49 26 4
gpt4 key购买 nike

我有一个 cxf JAX-WS 客户端。我添加了故障转移策略。问题是客户端如何从备份解决方案中恢复并再次使用主 URL?因为现在客户端切换到次要 URL 后仍会保留在那里,即使再次可用也不会使用主要 URL。

客户端部分的代码是:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(GatewayPort.class);
factory.setAddress(this.configFile.getPrimaryURL());

FailoverFeature feature = new FailoverFeature();
SequentialStrategy strategy = new SequentialStrategy();
List<String> addList = new ArrayList<String>();
addList.add(this.configFile.getSecondaryURL());
strategy.setAlternateAddresses(addList);
feature.setStrategy(strategy);

List<AbstractFeature> features = new ArrayList<AbstractFeature>();
features.add(feature);
factory.setFeatures(features);

this.serviceSoap = (GatewayPort)factory.create();

Client client = ClientProxy.getClient(this.serviceSoap);
if (client != null)
{
HTTPConduit conduit = (HTTPConduit)client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(this.configFile.getTimeout());
policy.setReceiveTimeout(this.configFile.getTimeout());
conduit.setClient(policy);
}

最佳答案

您可以将主要 URL 添加到备用地址列表,而不是将其设置为 JaxWsProxyFactoryBean。这样,由于您使用的是 SequentialStrategy,每次服务调用都会首先检查主 URL,如果失败,则会尝试辅助 URL。

关于apache - cxf 故障转移恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12728523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com