update easy-retry 3.1.0 => 3.1.1 增加日志自动推送配置与nacos自动发现server服务自动重试连接功能
parent
799739c16e
commit
5370d7785c
|
|
@ -37,6 +37,9 @@ easy-retry:
|
||||||
# 需要在EasyRetry后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
# 需要在EasyRetry后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
||||||
group-name: "ruoyi_group"
|
group-name: "ruoyi_group"
|
||||||
server:
|
server:
|
||||||
|
# 从 nacos 获取服务
|
||||||
|
server-name: ruoyi-easyretry-server
|
||||||
|
# 服务名优先 ip垫底
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 1788
|
port: 1788
|
||||||
# 详见 script/sql/easy_retry.sql `namespace` 表
|
# 详见 script/sql/easy_retry.sql `namespace` 表
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -35,7 +35,7 @@
|
||||||
<redisson.version>3.27.0</redisson.version>
|
<redisson.version>3.27.0</redisson.version>
|
||||||
<lock4j.version>2.2.7</lock4j.version>
|
<lock4j.version>2.2.7</lock4j.version>
|
||||||
<powerjob.version>4.3.6</powerjob.version>
|
<powerjob.version>4.3.6</powerjob.version>
|
||||||
<easyretry.version>3.1.0</easyretry.version>
|
<easyretry.version>3.1.1</easyretry.version>
|
||||||
<satoken.version>1.37.0</satoken.version>
|
<satoken.version>1.37.0</satoken.version>
|
||||||
<lombok.version>1.18.30</lombok.version>
|
<lombok.version>1.18.30</lombok.version>
|
||||||
<logstash.version>7.4</logstash.version>
|
<logstash.version>7.4</logstash.version>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,27 @@
|
||||||
package org.dromara.common.job.config;
|
package org.dromara.common.job.config;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Logger;
|
||||||
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.aizuda.easy.retry.client.common.appender.EasyRetryLogbackAppender;
|
||||||
|
import com.aizuda.easy.retry.client.common.event.ChannelReconnectEvent;
|
||||||
|
import com.aizuda.easy.retry.client.common.event.EasyRetryStartingEvent;
|
||||||
import com.aizuda.easy.retry.client.starter.EnableEasyRetry;
|
import com.aizuda.easy.retry.client.starter.EnableEasyRetry;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.job.config.properties.EasyRetryServerProperties;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动定时任务
|
* 启动定时任务
|
||||||
*
|
*
|
||||||
|
|
@ -12,8 +29,50 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
* @since 2024/3/12
|
* @since 2024/3/12
|
||||||
*/
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
|
@EnableConfigurationProperties(EasyRetryServerProperties.class)
|
||||||
@ConditionalOnProperty(prefix = "easy-retry", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "easy-retry", name = "enabled", havingValue = "true")
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableEasyRetry(group = "${easy-retry.group-name}")
|
@EnableEasyRetry(group = "${easy-retry.group-name}")
|
||||||
public class EasyRetryConfig {
|
public class EasyRetryConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EasyRetryServerProperties properties;
|
||||||
|
@Autowired
|
||||||
|
private DiscoveryClient discoveryClient;
|
||||||
|
|
||||||
|
@EventListener(EasyRetryStartingEvent.class)
|
||||||
|
public void onStarting(EasyRetryStartingEvent event) {
|
||||||
|
// 从 nacos 获取 server 服务连接
|
||||||
|
registerServer();
|
||||||
|
// 注册 日志监控配置
|
||||||
|
registerLogging();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventListener(ChannelReconnectEvent.class)
|
||||||
|
public void onReconnect(ChannelReconnectEvent event) {
|
||||||
|
// 连接中断 重新从 nacos 获取存活的服务连接(高可用配置)
|
||||||
|
registerServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerServer() {
|
||||||
|
String serverName = properties.getServerName();
|
||||||
|
if (StringUtils.isNotBlank(serverName)) {
|
||||||
|
List<ServiceInstance> instances = discoveryClient.getInstances(serverName);
|
||||||
|
if (CollUtil.isNotEmpty(instances)) {
|
||||||
|
ServiceInstance instance = instances.get(0);
|
||||||
|
System.setProperty("easy-retry.server.host", instance.getHost());
|
||||||
|
System.setProperty("easy-retry.server.port", properties.getPort());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerLogging() {
|
||||||
|
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||||
|
EasyRetryLogbackAppender<ILoggingEvent> ca = new EasyRetryLogbackAppender<>();
|
||||||
|
ca.setName("easy_log_appender");
|
||||||
|
ca.start();
|
||||||
|
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||||
|
rootLogger.addAppender(ca);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.dromara.common.job.config.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ConfigurationProperties(prefix = "easy-retry.server")
|
||||||
|
public class EasyRetryServerProperties {
|
||||||
|
|
||||||
|
private String serverName;
|
||||||
|
|
||||||
|
private String port;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue