Commit 37343ed9 by 房斌

1优化超时问题

2版本加载判断
3停机组件加载判断
parent 130068a9
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
package com.secoo.mall.dubbo.monitor.config; package com.secoo.mall.dubbo.monitor.config;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.dubbo.monitor.dubbo.Constants.Constants; import com.secoo.mall.dubbo.monitor.dubbo.Constants.Constants;
import com.secoo.mall.dubbo.monitor.dubbo.exception.ConfigurationException; import com.secoo.mall.dubbo.monitor.dubbo.exception.ConfigurationException;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.extension.ExtensionLoader;
...@@ -34,8 +36,6 @@ import org.springframework.context.annotation.Configuration; ...@@ -34,8 +36,6 @@ import org.springframework.context.annotation.Configuration;
public class ConfigCenter { public class ConfigCenter {
public static final Logger logger = LoggerFactory.getLogger(ConfigCenter.class);
@Value("${dubbo.registry.address:}") @Value("${dubbo.registry.address:}")
public String registryAddress; public String registryAddress;
@Value("${dubbo.protocol.name}") @Value("${dubbo.protocol.name}")
...@@ -46,6 +46,8 @@ public class ConfigCenter { ...@@ -46,6 +46,8 @@ public class ConfigCenter {
public String password; public String password;
@Value("${dubbo.monitorpatch:}") @Value("${dubbo.monitorpatch:}")
public String patch; public String patch;
@Value("${dubbo.application.timeout:}")
public String timeout;
public URL registryUrl; public URL registryUrl;
@Bean @Bean
...@@ -55,7 +57,8 @@ public class ConfigCenter { ...@@ -55,7 +57,8 @@ public class ConfigCenter {
if (StringUtils.isBlank(registryAddress)) { if (StringUtils.isBlank(registryAddress)) {
throw new ConfigurationException("Either config center or registry address is needed, please refer to https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration"); throw new ConfigurationException("Either config center or registry address is needed, please refer to https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration");
} }
registryUrl = formUrl(registryAddress, registryGroup, username, password);
registryUrl = formUrl(registryAddress, registryGroup, username, password,timeout);
// registryUrl.setPath(patch); // registryUrl.setPath(patch);
} }
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension(); RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
...@@ -63,11 +66,17 @@ public class ConfigCenter { ...@@ -63,11 +66,17 @@ public class ConfigCenter {
return registry; return registry;
} }
public URL formUrl(String config, String group, String username, String password) { public URL formUrl(String config, String group, String username, String password,String timeout) {
URL url = URL.valueOf(config); URL url = URL.valueOf(config);
if (StringUtils.isNotEmpty(group)) { if (StringUtils.isNotEmpty(group)) {
url = url.addParameter(Constants.GROUP_KEY, group); url = url.addParameter(Constants.GROUP_KEY, group);
} }
if(StringUtil.isEmpty(timeout)){
url=url.addParameter("timeout",20000);
}else{
url=url.addParameter("timeout", Integer.valueOf(timeout).intValue());
}
if (StringUtils.isNotEmpty(username)) { if (StringUtils.isNotEmpty(username)) {
url = url.setUsername(username); url = url.setUsername(username);
} }
......
...@@ -44,7 +44,6 @@ public class GracefulShutDown implements CommandLineRunner, ApplicationListener< ...@@ -44,7 +44,6 @@ public class GracefulShutDown implements CommandLineRunner, ApplicationListener<
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
logger.info("dddddddddddddduuuuuuuuuuuuuuuuubbbbbbbbbbbboooooooooooolllllllllll!!!!"); logger.info("dddddddddddddduuuuuuuuuuuuuuuuubbbbbbbbbbbboooooooooooolllllllllll!!!!");
if (DubboShutdownHook.getDubboShutdownHook() != null) { if (DubboShutdownHook.getDubboShutdownHook() != null) {
//TODO 判断是否dubbo组件,如果没有就不执行卸载和 shutDownhook
//hock卸载 //hock卸载
DubboShutdownHook.getDubboShutdownHook().unregister(); DubboShutdownHook.getDubboShutdownHook().unregister();
//listener 卸载 //listener 卸载
......
...@@ -56,7 +56,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -56,7 +56,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
public ExecutorDetail stop() { public ExecutorDetail stop() {
ExecutorDetail detail = new ExecutorDetail(); ExecutorDetail detail = new ExecutorDetail();
detail.setBeginTime(DateUtil.getDateTime()); detail.setBeginTime(DateUtil.getDateTime());
detail.setServiceName("dubboDownHock1045"); detail.setServiceName("dubboDownHock1046");
List<String> str = new ArrayList<String>(); List<String> str = new ArrayList<String>();
detail.setDetail(str); detail.setDetail(str);
detail.setCode(0); detail.setCode(0);
......
...@@ -38,7 +38,7 @@ public class MatrixGracefulShutDownAutoConfiguration { ...@@ -38,7 +38,7 @@ public class MatrixGracefulShutDownAutoConfiguration {
@DependsOn("configCenter") @DependsOn("configCenter")
UpDatas dubboUpdata( ConfigCenter configCenter){ UpDatas dubboUpdata( ConfigCenter configCenter){
ShutDownDataReport transport= new ShutDownDataReport(); ShutDownDataReport transport= new ShutDownDataReport();
URL url =configCenter.formUrl(configCenter.registryAddress, configCenter.registryGroup, configCenter.username, configCenter.password); URL url =configCenter.formUrl(configCenter.registryAddress, configCenter.registryGroup, configCenter.username, configCenter.password,configCenter.timeout);
transport.setUrl(url); transport.setUrl(url);
if(StringUtil.isEmpty(configCenter.patch)){ if(StringUtil.isEmpty(configCenter.patch)){
configCenter.patch="/monitorZ"; configCenter.patch="/monitorZ";
...@@ -75,18 +75,23 @@ public class MatrixGracefulShutDownAutoConfiguration { ...@@ -75,18 +75,23 @@ public class MatrixGracefulShutDownAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnClass(TomcatConnectorCustomizer.class) @ConditionalOnClass({TomcatGracefulShutDown.class,org.apache.catalina.connector.Connector.class})
@SpringBootVersionJudgment()
TomcatShutDownHook createServletConnectShoutDownHock() { TomcatShutDownHook createServletConnectShoutDownHock() {
return new TomcatShutDownHook(); return new TomcatShutDownHook();
} }
@Bean @Bean
@ConditionalOnClass(TomcatShutDownHook.class) @ConditionalOnClass(org.apache.catalina.connector.Connector.class)
@SpringBootVersionJudgment()
public TomcatGracefulShutDown createSpringbootTomcatInit(TomcatShutDownHook tomcatShutDownHook){ public TomcatGracefulShutDown createSpringbootTomcatInit(TomcatShutDownHook tomcatShutDownHook){
return new TomcatGracefulShutDown(tomcatShutDownHook); return new TomcatGracefulShutDown(tomcatShutDownHook);
} }
@Bean @Bean
@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')") @ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')")
public GracefulShutDown createGraceObject(UpDatas dubboUpdata) { public GracefulShutDown createGraceObject(UpDatas dubboUpdata) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment