[
https://issues.apache.org/jira/browse/CXF-5745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14001472#comment-14001472
]
Xilai Dai commented on CXF-5745:
--------------------------------
That's the default behaviour of FailoverTargetSelector (not sure it's a bug or
by design), but you may do some extension to match your requirement.
1) provide a MySequentialStrategy which extends SequentialStrategy
{code}
public class MySequentialStrategy extends SequentialStrategy {
......
public String getPrimaryAddress(Exchange exchange) {
......
return primaryUrl;
}
......
}
{code}
2) provide a MyTargetSelector which extends FailoverTargetSelector
{code}
import org.apache.cxf.clustering.FailoverTargetSelector;
......
public class MyTargetSelector extends FailoverTargetSelector {
@Override
public synchronized void prepare(Message message) {
setAddress(message);
super.prepare(message);
}
private void setAddress(Message message) {
String primaryUrl = strategy.getPrimaryAddress(message.getExchange());
if (primaryUrl != null) {
endpoint.getEndpointInfo().setAddress(primaryUrl);
message.put(Message.ENDPOINT_ADDRESS, primaryUrl);
}
}
}
{code}
3) provide a MyFailoverFeature:
{code}
public class MyFailoverFeature extends AbstractFeature {
......
@Override
public void initialize(InterceptorProvider interceptorProvider, Bus bus) {
if (interceptorProvider instanceof ConduitSelectorHolder) {
ConduitSelectorHolder conduitSelectorHolder =
(ConduitSelectorHolder)interceptorProvider;
MyTargetSelector selector = new MyTargetSelector();
selector.setEndpoint(conduitSelectorHolder.getConduitSelector().getEndpoint());
selector.setStrategy(mySequentialStrategy);
conduitSelectorHolder.setConduitSelector(selector);
}
}
......
}
{code}
then, add this MyFailoverFeature into your JaxWsProxyFactoryBean.
> CXF Failover feature does not return to primary URL. It returns to first in
> failover urls.
> ------------------------------------------------------------------------------------------
>
> Key: CXF-5745
> URL: https://issues.apache.org/jira/browse/CXF-5745
> Project: CXF
> Issue Type: Bug
> Components: JAX-WS Runtime
> Affects Versions: 2.7.5
> Reporter: Jan Zanda
> Priority: Minor
>
> I have a WS consumer, which uses one primary URL and up to 8 failover urls.
> The consumer is created this way (see also comments in code):
> {noformat}
> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
> factory.setServiceClass(SomeClientClass.class);
> factory.setAddress(primaryUrl); // this is http://primaryhost/service
> factory.setFeatures(getFailoverFeatures());
> List<AbstractFeature> getFailoverFeatures() {
> FailoverFeature feature = new FailoverFeature();
> SequentialStrategy strategy = new SequentialStrategy();
> strategy.setAlternateAddresses(failoverUrls); //failoverUrls is a List of
> urls.
> // something like {'http://failoverOne/service',
> 'http://failoverTwo/service'}
> feature.setStrategy(strategy);
> List<AbstractFeature> features = new ArrayList<AbstractFeature>();
> features.add(feature);
> return features;
> }
> {noformat}
> However, when application run out of failover URLs, it will write to log this:
> {noformat}
> 2014-05-16 09:00:03,473 WARN [AbstractStaticFailoverStrategy] no alternate
> targets remain => giving up on failover
> 2014-05-16 09:00:03,473 INFO [FailoverTargetSelector] reverted to original
> address http://failoverOne/service
> {noformat}
> Is there a way how to tell the failover feature to rotate ALL of the urls,
> primary URL included?
> Thanks.
--
This message was sent by Atlassian JIRA
(v6.2#6252)