mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-04 19:38:02 +00:00
update easy-retry 3.1.0 => 3.1.1 增加日志自动推送配置与nacos自动发现server服务自动重试连接功能
This commit is contained in:
@@ -37,6 +37,9 @@ easy-retry:
|
||||
# 需要在EasyRetry后台组管理创建对应名称的组,然后创建任务的时候选择对应的组,才能正确分派任务
|
||||
group-name: "ruoyi_group"
|
||||
server:
|
||||
# 从 nacos 获取服务
|
||||
server-name: ruoyi-easyretry-server
|
||||
# 服务名优先 ip垫底
|
||||
host: 127.0.0.1
|
||||
port: 1788
|
||||
# 详见 script/sql/easy_retry.sql `namespace` 表
|
||||
|
2
pom.xml
2
pom.xml
@@ -35,7 +35,7 @@
|
||||
<redisson.version>3.27.0</redisson.version>
|
||||
<lock4j.version>2.2.7</lock4j.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>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<logstash.version>7.4</logstash.version>
|
||||
|
@@ -1,10 +1,27 @@
|
||||
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 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.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 java.util.List;
|
||||
|
||||
/**
|
||||
* 启动定时任务
|
||||
*
|
||||
@@ -12,8 +29,50 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
* @since 2024/3/12
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(EasyRetryServerProperties.class)
|
||||
@ConditionalOnProperty(prefix = "easy-retry", name = "enabled", havingValue = "true")
|
||||
@EnableScheduling
|
||||
@EnableEasyRetry(group = "${easy-retry.group-name}")
|
||||
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;
|
||||
|
||||
}
|
Reference in New Issue
Block a user