-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support Spring RestClient as TransportClientFactory #4281
Conversation
Add related classes - `RestClientDiscoveryClientOptionalArgs` - `RestClientEurekaHttpClient` - `RestClientTransportClientFactories` - `RestClientTransportClientFactory` Add property - `eureka.client.restclient.enabled` (default `false`) Change auto-configure - `RestTemplate`-related settings for `webclient.enabled=false` have been removed. `restclient.enabled` makes it meaningless Move commonly used classes - `NotFoundHttpResponse` - `EurekaHttpClientUtils` Edit the document Added similar tests referring to `RestTemplate` and `WebClient`
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Outdated
Show resolved
Hide resolved
Could you please inform me if there are any plans to phase out |
FYI) target issue: #4257 |
gentle ping 😄 |
Thanks @heowc, will take a look. We do not have a plan for phasing out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @heowc. So far, have only looked at the docs - please implement the suggestion. Will continue the review of this PR tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @heowc. Have added some comments - please take a look. Will continue this review tomorrow.
...rg/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java
Show resolved
Hide resolved
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Show resolved
Hide resolved
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Outdated
Show resolved
Hide resolved
Fixes gh-4257. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working on it @heowc. This concludes the first review pass on this PR. Please address the comments I've added and let me know when it's ready for another pass.
Also, please make sure to update the date in license file comments in all the classes you've modified to end with -2022
, add your full name and surname with the @author
tag to the javadocs to all the classes you've modified, and add @since 4.1.3
to the javadocs of all the production classes you've added.
...ava/org/springframework/cloud/netflix/eureka/http/RestClientDiscoveryClientOptionalArgs.java
Show resolved
Hide resolved
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Show resolved
Hide resolved
...ain/java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactory.java
Show resolved
Hide resolved
...lient/src/main/java/org/springframework/cloud/netflix/eureka/http/EurekaHttpClientUtils.java
Show resolved
Hide resolved
...java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactoryTest.java
Outdated
Show resolved
Hide resolved
...java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactoryTest.java
Outdated
Show resolved
Hide resolved
...java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactoryTest.java
Outdated
Show resolved
Hide resolved
...va/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTest.java
Outdated
Show resolved
Hide resolved
...va/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTest.java
Outdated
Show resolved
Hide resolved
# Conflicts: # docs/modules/ROOT/partials/_configprops.adoc # spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java # spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java # spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.../src/main/java/org/springframework/cloud/netflix/eureka/http/RestClientEurekaHttpClient.java
Outdated
Show resolved
Hide resolved
final ResponseEntity<String> response = restClient.get().uri("http://localhost:" + port).retrieve() | ||
.toEntity(String.class); | ||
|
||
assertThat(response).isNotNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that we're testing a call done by RestClient
, which is a component provided by Spring Framework and tested very well itself. What we should do is instead use RestClientEurekaHttpClient
to do the call, and then verify its result.
...ork/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationRestClientTests.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
@@ -109,6 +114,22 @@ public WebClientEurekaHttpClient configDiscoveryWebClientEurekaHttpClient(Eureka | |||
|
|||
} | |||
|
|||
@Configuration(proxyBeanMethods = false) | |||
@ConditionalOnClass(name = "org.springframework.web.client.RestClient") | |||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some more consideration, I actually think we could switch to using RestClient
by default in case of the non-blocking stack, so let's add matchIfMissing=true
and @ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
to the RestTemplate
-based configuration. Sorry for the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added related conditions while changing JerseyClientNotPresentOrNotEnabledCondition
to RestTemplateEnabledCondition
. Is this what you intended? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the logic after your changes has been modified - please take a look at the review comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is something I misunderstood, please let me know.
- Modify the
eureka.client.restclient.enabled
annotation I added as follows.
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true")
->
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "true", matchIfMissing = true)
- Then, set the following annotation to the configuration beans that are set based on
RestTemplate
.
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", havingValue = "false")
However, if I set it like this, some tests will fail. The reason is that matchIfMissing
is changed so that it should default to RestTemplate
, but it changes to RestClient
, or even RestTemplate
is not set, so the bean is not configured.
...etflix/eureka/config/EurekaConfigServerBootstrapConfigurationRestClientIntegrationTests.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @heowc. Have added additional comments. Please take a look.
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...amework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationClientTests.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @heowc, thanks for adding changes and comments. I have tried to further clarify the configuration setup by adding some comments to the code changes along with reasoning behind them. If possible, please add the changes discussed till the end of this week. If you don't have the time, no worries, however, since I want to make sure we get this feature into the upcoming RC, if this is not ready, then on Mon, I will cherry-pick your changes and add any necessary changes on top of them. Thank you for all your work on this PR (and others).
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@ConditionalOnProperty(prefix = "eureka.client", name = "restclient.enabled", matchIfMissing = true, | ||
havingValue = "false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be matchIfMissing=true
. Since we now want the RestClient
based implementation to be default, we only want to do RestTemplate
if RestClient
is explicitly disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was really hoping that the default would change while working on this issue (it's too complicated).
Is this direction related to the issue below?
#4347
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we would like to change the default here to RestClient
. That is why we don't want to use RestTemplate
unless RestClient
is explicitly disabled.
...rg/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
Outdated
Show resolved
Hide resolved
Thank you for reviewing this issue for a rather long time. I was fixed everything in response to your comments, but if you have any other suggestions, please let us know. Of course, there were some test modifications with the changed direction. Please take note. |
...ain/java/org/springframework/cloud/netflix/eureka/http/RestClientTransportClientFactory.java
Show resolved
Hide resolved
Hello @OlgaMaciaszek, See #4281 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @heowc. Thanks for relentlessly working on this.
Nice work @heowc !!! also thanks for the kind review @OlgaMaciaszek 👍👍👍 |
Change
RestClient
to default eureka client. This changes the default behavior.RestTemplate
toRestClient
Add related classes
RestClientDiscoveryClientOptionalArgs
RestClientEurekaHttpClient
RestClientTransportClientFactories
RestClientTransportClientFactory
Add property
eureka.client.restclient.enabled
(defaultfalse
)Move commonly used classes
NotFoundHttpResponse
EurekaHttpClientUtils
Edit the document
Added similar tests referring to
RestTemplate
andWebClient
Close #4257