Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Spring Retry For Failed Requests Using Feign #1457

Merged
merged 7 commits into from
Jan 10, 2017
Merged

Use Spring Retry For Failed Requests Using Feign #1457

merged 7 commits into from
Jan 10, 2017

Conversation

ryanjbaxter
Copy link
Contributor

Part of our continued effort to unify retry logic in Spring Cloud around Spring Retry. Ties back to #1290.

@ryanjbaxter
Copy link
Contributor Author

This is not likely ready for prime time but I wanted to get some eyes on these changes.

@ryanjbaxter
Copy link
Contributor Author

spring-cloud/spring-cloud-sleuth#446 is dependent on this change

@ryanjbaxter
Copy link
Contributor Author

One last comment ;)

These changes will also need to be merged into the 1.3.x branch.

@codecov-io
Copy link

codecov-io commented Nov 10, 2016

Current coverage is 74.36% (diff: 76.56%)

Merging #1457 into 1.2.x will decrease coverage by 0.20%

@@              1.2.x      #1457   diff @@
==========================================
  Files           189        190     +1   
  Lines          5834       5886    +52   
  Methods           0          0          
  Messages          0          0          
  Branches        884        888     +4   
==========================================
+ Hits           4350       4377    +27   
- Misses         1166       1191    +25   
  Partials        318        318          

Powered by Codecov. Last update 19556dc...5cd39df

@@ -16,6 +16,13 @@

package org.springframework.cloud.netflix.feign;

import com.netflix.hystrix.HystrixCommand;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd. Why a bunch of new imports?

Response response = request.client().execute(request.toRequest(), options);
return new RibbonResponse(request.getUri(), response);
LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this);
retryTemplate.setRetryPolicy(retryPolicy == null ? new NeverRetryPolicy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this should only be done once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the request when creating the policy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still confused about where the request is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you are saying that the policy should only be created once? The problem is we need the Request when FeignRetryPolicy.open is called so we can set the ServiceInstance in the Retry Context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, the retry policy created below uses the request. Could there be a problem since the retry policy is scoped to the request and the template is a field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to make sure I understand the concern....

If multiple requests are executed simultaneously you are concerned about switching out the retry policy mid request?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my worry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I guess the only good solution for now is to create a new RetryTemplate for each request. I don't see any real downside to that, but I do think it can be handled better by Spring Retry. I posed this in issue spring-projects/spring-retry#71.

@@ -71,7 +68,7 @@
* Flag for whether retry is supported by default (assuming the routes themselves
* support it).
*/
private Boolean retryable;
private Boolean retryable = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated.


private volatile Map<String, FeignLoadBalancer> cache = new ConcurrentReferenceHashMap<>();

public CachingSpringLoadBalancerFactory(SpringClientFactory factory) {
public CachingSpringLoadBalancerFactory(SpringClientFactory factory, RetryTemplate retryTemplate,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the old signature for backwards compatibility.

@@ -16,8 +16,12 @@

package org.springframework.cloud.netflix.ribbon.apache;

import java.net.URI;

import com.netflix.client.RequestSpecificRetryHandler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fix your ordering in a number of files ;-)

…s per request

-Fixed imports
-Addressed other code review concerns
@ryanjbaxter
Copy link
Contributor Author

@spencergibb can you take another look when you get a chance?

@@ -107,7 +106,7 @@ public FormattingConversionService feignConversionService() {
@Scope("prototype")
@ConditionalOnMissingBean
public Feign.Builder feignBuilder() {
return Feign.builder();
return Feign.builder().retryer(Retryer.NEVER_RETRY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in a @Bean definition.

Response response = request.client().execute(request.toRequest(), options);
return new RibbonResponse(request.getUri(), response);
LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this);
retryTemplate.setRetryPolicy(retryPolicy == null ? new NeverRetryPolicy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still confused about where the request is used.

… dependent on the request. We don’t want two Feign requests stomping on each other by switching out the retry policy for the template so each request now created a new template to use.
@ryanjbaxter ryanjbaxter merged commit 470d6ab into spring-cloud:1.2.x Jan 10, 2017
ryanjbaxter added a commit that referenced this pull request Jan 10, 2017
ryanjbaxter added a commit that referenced this pull request Feb 9, 2017
ryanjbaxter added a commit that referenced this pull request Feb 9, 2017
@ryanjbaxter ryanjbaxter deleted the feign-retry branch September 26, 2017 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants