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

[ISSUE #3094]abstract create nacos restTemplate factory #3095

Merged
merged 5 commits into from
Jun 17, 2020
Merged

[ISSUE #3094]abstract create nacos restTemplate factory #3095

merged 5 commits into from
Jun 17, 2020

Conversation

Maijh97
Copy link
Collaborator

@Maijh97 Maijh97 commented Jun 17, 2020

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

fix: #3094
When using nacos templates,can customize common parameters of http client, such as timeout time and connection time.

  • Add HttpClientFactory interface to create NacosRestTemplate and NacosAsyncRestTemplate
  • Abstract the AbstractHttpClientFactoryWrapper class, encapsulate the method created, provide custom http client config method
  • Defines a unified http client config class
  • Defines the tool class creates NacosRestTemplate and NacosAsyncRestTemplate

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

Maijh97 added 4 commits June 17, 2020 15:47
# Conflicts:
#	common/src/main/java/com/alibaba/nacos/common/http/HttpClientManager.java
@KomachiSion
Copy link
Collaborator

  1. Please change your title with [ISSUE #XXX] xxx.
  2. And refer your issue in your description.
  3. update your finished checklist.

@Maijh97
Copy link
Collaborator Author

Maijh97 commented Jun 17, 2020

本来打算替换客户端的http client使用,但是发现每个使用的http client都有自己独有配置参数。为了保证PR内容尽量少,我这边暂时先不做替换的工作,先把nacos template创建重新抽象了,在这个PR合并之后,我将会继续替换客户端http client的任务,麻烦 @chuntaojun @KomachiSion 同学帮忙review该PR。谢谢

@Maijh97 Maijh97 changed the title abstract create nacos restTemplate factory [ISSUE #3094]abstract create nacos restTemplate factory Jun 17, 2020
Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

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

Good job for all implementation.

I comment some problem. Change please

* @date 2020/6/16
*/
@SuppressWarnings("all")
public final class HttpClientBeanFactory {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename to HttpClientBeanCache or HttpClientBeanHolder will be better.


public static NacosRestTemplate getNacosRestTemplate() {
HttpClientFactory httpClientFactory = new DefaultHttpClientConfig();
return getNacosRestTemplate(httpClientFactory);
Copy link
Collaborator

Choose a reason for hiding this comment

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

merge these line to single line to remove tmp variable.

like return getNacosRestTemplate(new DefaultHttpClientConfig());


public static NacosAsyncRestTemplate getNacosAsyncRestTemplate() {
HttpClientFactory httpClientFactory = new DefaultHttpClientConfig();
return getNacosAsyncRestTemplate(httpClientFactory);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above description.

* @author mai.jh
* @date 2020/6/15
*/
public abstract class AbstractHttpClientFactoryWrapper implements HttpClientFactory {
Copy link
Collaborator

Choose a reason for hiding this comment

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

AbstractHttpClientFactory is enough.

return HttpClientBeanFactory.getNacosRestTemplate(HTTP_CLIENT_FACTORY);
}

private static class NamingHttpClientConfig extends AbstractHttpClientFactoryWrapper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NamingHttpClientFactory will be better. NamingHttpClientConfig make other think it is a config pojo.

* @author mai.jh
* @date 2020/6/15
*/
public class DefaultHttpClientConfig extends AbstractHttpClientFactoryWrapper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same problem as NamingHttpClientConfig. DefaultHttpClientFactory will be better.

@@ -55,4 +55,6 @@ public void onEvent(Event event) {
}
});
}


Copy link
Collaborator

Choose a reason for hiding this comment

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

Why add this two blank line? Please remove.

@KomachiSion KomachiSion added this to the 1.3.1 milestone Jun 17, 2020
@KomachiSion KomachiSion merged commit e528ea8 into alibaba:develop Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

abstract create nacos restTemplate factory
2 participants