refactor:0.0.4.2
激活x-retry-core组件,使用ConditionalOnProperty模式启动
This commit is contained in:
parent
0ef6d6c58b
commit
5ffead5c53
@ -38,7 +38,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.byteblogs</groupId>
|
<groupId>com.byteblogs</groupId>
|
||||||
<artifactId>x-retry-client-starter</artifactId>
|
<artifactId>x-retry-client-starter</artifactId>
|
||||||
<version>0.0.4.1</version>
|
<version>0.0.4.2-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
|
@ -22,7 +22,7 @@ import java.util.Set;
|
|||||||
* @date : 2022-05-02 21:06
|
* @date : 2022-05-02 21:06
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Order()
|
@Order
|
||||||
public class GroupVersionCache implements Lifecycle {
|
public class GroupVersionCache implements Lifecycle {
|
||||||
|
|
||||||
public static ConfigDTO configDTO;
|
public static ConfigDTO configDTO;
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.x.retry.client.core.config;
|
package com.x.retry.client.core.config;
|
||||||
|
|
||||||
|
import com.x.retry.common.core.context.SpringContext;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: www.byteblogs.com
|
* @author: www.byteblogs.com
|
||||||
* @date : 2022-03-04 15:53
|
* @date : 2022-03-04 15:53
|
||||||
@ -19,7 +23,7 @@ public class XRetryProperties {
|
|||||||
/**
|
/**
|
||||||
* 服务端对应的group
|
* 服务端对应的group
|
||||||
*/
|
*/
|
||||||
private static String group;
|
private String group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务端配置
|
* 服务端配置
|
||||||
@ -28,15 +32,19 @@ public class XRetryProperties {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class ServerConfig {
|
public static class ServerConfig {
|
||||||
|
/**
|
||||||
|
* 服务端的地址,若服务端集群部署则此处配置域名
|
||||||
|
*/
|
||||||
private String host = "127.0.0.1";
|
private String host = "127.0.0.1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端netty的端口号
|
||||||
|
*/
|
||||||
private int port = 1788;
|
private int port = 1788;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGroup(String group) {
|
|
||||||
XRetryProperties.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getGroup() {
|
public static String getGroup() {
|
||||||
return group;
|
XRetryProperties properties = SpringContext.applicationContext.getBean(XRetryProperties.class);
|
||||||
|
return Objects.requireNonNull(properties).group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import java.lang.annotation.*;
|
|||||||
@Target({ElementType.TYPE})
|
@Target({ElementType.TYPE})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Import({XRetryClientConfig.class, XRetryClientsRegistrar.class})
|
@Import(XRetryClientsRegistrar.class)
|
||||||
public @interface EnableXRetry {
|
public @interface EnableXRetry {
|
||||||
|
|
||||||
String group();
|
String group();
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.x.retry.client.starter;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan("com.x.retry.client.core")
|
||||||
|
@ConditionalOnProperty(prefix = "x-retry", name = "enabled", havingValue = "true")
|
||||||
|
public class XRetryClientAutoConfiguration {
|
||||||
|
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
package com.x.retry.client.starter;
|
|
||||||
|
|
||||||
import com.x.retry.client.core.config.XRetryProperties;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ComponentScan("com.x.retry.client.core")
|
|
||||||
public class XRetryClientConfig {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setRetryProperties(XRetryProperties retryProperties) {
|
|
||||||
XRetryProperties.setGroup(XRetryClientsRegistrar.GROUP);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,10 @@
|
|||||||
package com.x.retry.client.starter;
|
package com.x.retry.client.starter;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
import org.springframework.context.EnvironmentAware;
|
||||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -10,13 +13,22 @@ import java.util.Map;
|
|||||||
* @author: www.byteblogs.com
|
* @author: www.byteblogs.com
|
||||||
* @date : 2022-03-04 18:44
|
* @date : 2022-03-04 18:44
|
||||||
*/
|
*/
|
||||||
public class XRetryClientsRegistrar implements ImportBeanDefinitionRegistrar {
|
public class XRetryClientsRegistrar implements ImportBeanDefinitionRegistrar, EnvironmentAware {
|
||||||
|
|
||||||
public static String GROUP = "";
|
private StandardEnvironment standardEnvironment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||||
Map<String, Object> attrs = importingClassMetadata.getAnnotationAttributes(EnableXRetry.class.getName());
|
Map<String, Object> attrs = importingClassMetadata.getAnnotationAttributes(EnableXRetry.class.getName());
|
||||||
XRetryClientsRegistrar.GROUP = (String) attrs.get("group");
|
Map<String, Object> systemEnvironment = standardEnvironment.getSystemProperties();
|
||||||
|
systemEnvironment.put("x-retry.group", (String) attrs.get("group"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnvironment(Environment environment) {
|
||||||
|
StandardEnvironment standardEnvironment = (StandardEnvironment) environment;
|
||||||
|
this.standardEnvironment = standardEnvironment;
|
||||||
|
Map<String, Object> systemEnvironment = standardEnvironment.getSystemProperties();
|
||||||
|
systemEnvironment.put("x-retry.enabled", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.x.retry.client.starter.XRetryClientConfig
|
com.x.retry.client.starter.XRetryClientAutoConfiguration
|
||||||
|
@ -35,7 +35,7 @@ public class ShedlockConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public TaskScheduler scheduledExecutorService() {
|
public TaskScheduler scheduledExecutorService() {
|
||||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||||
scheduler.setPoolSize(8);
|
scheduler.setPoolSize(2);
|
||||||
scheduler.setThreadNamePrefix("x-retry-scheduled-thread-");
|
scheduler.setThreadNamePrefix("x-retry-scheduled-thread-");
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user