[
https://issues.apache.org/jira/browse/CXF-8286?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17114430#comment-17114430
]
Andriy Redko edited comment on CXF-8286 at 5/22/20, 10:14 PM:
--------------------------------------------------------------
[~kwin]I I have created a simple test case [1]
{code:java}
@Test
public void testRetryFailover() throws Exception {
String address = "http://localhost:" + PORT1 + "/bookstore/unavailable";
final FailoverFeature feature = new FailoverFeature();
RetryStrategy strategy = new RetryStrategy();
strategy.setAlternateAddresses(Arrays.asList(address));
strategy.setMaxNumberOfRetries(5);
feature.setStrategy(strategy);
final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
bean.setFeatures(Arrays.asList(feature));
bean.setServiceClass(FailoverBookStore.class);
WebClient webClient = bean.createWebClient();
final Book b = webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
assertEquals(address, webClient.getBaseURI().toString());
}
{code}
Where the server return 4 times the 503, and succeeds on the 5th attempt. The
way failover implementation works, it favors *getAlternateAddresses()* vs
*getAlternateEndpoints()*: if alternate addresses are set, the alternate
endpoints are not consulted. Could you please submit the testcase so I can
clearly reproduce the issues why
*setAlternateAddresses/g**etAlternateAddresses* (this is a workaround for now)
do not work for you, thanks.
[1]
[https://github.com/apache/cxf/blob/master/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java#L97]
was (Author: reta):
[~kwin]I I have created a simple test case [1]
{code:java}
@Test
public void testRetryFailover() throws Exception {
String address = "http://localhost:" + PORT1 + "/bookstore/unavailable";
final FailoverFeature feature = new FailoverFeature();
RetryStrategy strategy = new RetryStrategy();
strategy.setAlternateAddresses(Arrays.asList(address));
strategy.setMaxNumberOfRetries(5);
feature.setStrategy(strategy);
final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress(address);
bean.setFeatures(Arrays.asList(feature));
bean.setServiceClass(FailoverBookStore.class);
WebClient webClient = bean.createWebClient();
final Book b = webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
assertEquals(address, webClient.getBaseURI().toString());
}
{code}
Where the server return 4 times the 503, and succeeds on the 5th attempt. The
way failover implementation works, it favors *getAlternateAddresses()* vs
*getAlternateEndpoints()*: if alternate addresses are set, the alternate
endpoints are not consulted. Could you please submit the testcase so I can
clearly reproduce the issues why
*setAlternateAddresses/g**etAlternateAddresses*** do not work for you, thanks.
[1]
[https://github.com/apache/cxf/blob/master/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java#L97]
> AbstractStaticFailoverStrategy.getEndpoints() never returns anything for
> JAX-RS clients (with RetryStrategy)
> ------------------------------------------------------------------------------------------------------------
>
> Key: CXF-8286
> URL: https://issues.apache.org/jira/browse/CXF-8286
> Project: CXF
> Issue Type: Improvement
> Affects Versions: 3.3.6, 3.2.13
> Reporter: Konrad Windszus
> Assignee: Andriy Redko
> Priority: Major
>
> When creating a JAX-RS client like described in
> https://cxf.apache.org/docs/jax-rs-failover.html with
> {code}
> JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
> bean.setAddress(API_BASE_ADDRESS);
> FailoverFeature failoverFeature = new CircuitBreakerFailoverFeature();
> RetryStrategy retryStrategy = new RetryStrategy();
> retryStrategy.setMaxNumberOfRetries(3);
> failoverFeature.setStrategy(retryStrategy);
> bean.setFeatures(Collection.singletonList(failureFeature));
> WebClient webClient = bean.createWebClient();
>
> T proxy = JAXRSClientFactory.fromClient(webClient, clazz);
> {code}
> The method
> https://github.com/apache/cxf/blob/517b88cb2c293115e0dce1c1105f448e9dc21164/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java#L133
> always returns an empty list (due to the
> https://github.com/apache/cxf/blob/517b88cb2c293115e0dce1c1105f448e9dc21164/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java#L135
> getting the empty list from
> https://github.com/apache/cxf/blob/38582fbab7ca33b1383715f1f5094b9b46a0303f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java#L112).
> Why is the endpoints/services not correctly set up for Jax RS clients for the
> failover handling to work. What else do I need to do here?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)