mirror of https://github.com/jeecgboot/jeecg-boot
【v3.8.3】undertow不稳定切换回tomcat
parent
4f46213df6
commit
f087525a75
|
@ -23,7 +23,7 @@ public class ShiroCacheClearRunner implements ApplicationRunner {
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
// 清空所有授权redis缓存
|
// 清空所有授权redis缓存
|
||||||
log.info("———————清空所有用户授权缓存———————clearAllCache——————— ");
|
log.info("——— Service restart, clearing all user shiro authorization cache ——— ");
|
||||||
redisUtil.removeAll(CommonConstant.PREFIX_USER_SHIRO_CACHE);
|
redisUtil.removeAll(CommonConstant.PREFIX_USER_SHIRO_CACHE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
//package org.jeecg.config.init;
|
package org.jeecg.config.init;
|
||||||
//
|
|
||||||
//import org.apache.catalina.Context;
|
import org.apache.catalina.Context;
|
||||||
//import org.apache.tomcat.util.scan.StandardJarScanner;
|
import org.apache.tomcat.util.scan.StandardJarScanner;
|
||||||
//import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||||
//import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
//import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @Description: TomcatFactoryConfig
|
* @Description: TomcatFactoryConfig
|
||||||
// * @author: scott
|
* @author: scott
|
||||||
// * @date: 2021年01月25日 11:40
|
* @date: 2021年01月25日 11:40
|
||||||
// */
|
*/
|
||||||
//@Configuration
|
@Configuration
|
||||||
//public class TomcatFactoryConfig {
|
public class TomcatFactoryConfig {
|
||||||
// /**
|
/**
|
||||||
// * tomcat-embed-jasper引用后提示jar找不到的问题
|
* tomcat-embed-jasper引用后提示jar找不到的问题
|
||||||
// */
|
*/
|
||||||
// @Bean
|
@Bean
|
||||||
// public TomcatServletWebServerFactory tomcatFactory() {
|
public TomcatServletWebServerFactory tomcatFactory() {
|
||||||
// TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
|
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
|
||||||
// @Override
|
@Override
|
||||||
// protected void postProcessContext(Context context) {
|
protected void postProcessContext(Context context) {
|
||||||
// ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
|
((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// factory.addConnectorCustomizers(connector -> {
|
factory.addConnectorCustomizers(connector -> {
|
||||||
// connector.setProperty("relaxedPathChars", "[]{}");
|
connector.setProperty("relaxedPathChars", "[]{}");
|
||||||
// connector.setProperty("relaxedQueryChars", "[]{}");
|
connector.setProperty("relaxedQueryChars", "[]{}");
|
||||||
// });
|
});
|
||||||
// return factory;
|
return factory;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
|
@ -1,48 +1,48 @@
|
||||||
package org.jeecg.config.init;
|
//package org.jeecg.config.init;
|
||||||
|
//
|
||||||
import io.undertow.UndertowOptions;
|
//import io.undertow.UndertowOptions;
|
||||||
import io.undertow.server.DefaultByteBufferPool;
|
//import io.undertow.server.DefaultByteBufferPool;
|
||||||
import io.undertow.server.handlers.BlockingHandler;
|
//import io.undertow.server.handlers.BlockingHandler;
|
||||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
//import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||||
import org.jeecg.modules.monitor.actuator.undertow.CustomUndertowMetricsHandler;
|
//import org.jeecg.modules.monitor.actuator.undertow.CustomUndertowMetricsHandler;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
//import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
//import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Undertow配置
|
// * Undertow配置
|
||||||
*
|
// *
|
||||||
* 解决启动提示: WARN io.undertow.websockets.jsr:68 - UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
|
// * 解决启动提示: WARN io.undertow.websockets.jsr:68 - UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
|
||||||
*/
|
// */
|
||||||
@Configuration
|
//@Configuration
|
||||||
public class UndertowConfiguration implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
//public class UndertowConfiguration implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 自定义undertow监控指标工具类
|
// * 自定义undertow监控指标工具类
|
||||||
* for [QQYUN-11902]tomcat 替换undertow 这里的功能还没修改
|
// * for [QQYUN-11902]tomcat 替换undertow 这里的功能还没修改
|
||||||
*/
|
// */
|
||||||
@Autowired
|
// @Autowired
|
||||||
private CustomUndertowMetricsHandler customUndertowMetricsHandler;
|
// private CustomUndertowMetricsHandler customUndertowMetricsHandler;
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void customize(UndertowServletWebServerFactory factory) {
|
// public void customize(UndertowServletWebServerFactory factory) {
|
||||||
// 设置 Undertow 服务器参数(底层网络配置)
|
// // 设置 Undertow 服务器参数(底层网络配置)
|
||||||
factory.addBuilderCustomizers(builder -> {
|
// factory.addBuilderCustomizers(builder -> {
|
||||||
builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE, 65536); // header 最大64KB
|
// builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE, 65536); // header 最大64KB
|
||||||
builder.setServerOption(UndertowOptions.MAX_PARAMETERS, 10000); // 最大参数数
|
// builder.setServerOption(UndertowOptions.MAX_PARAMETERS, 10000); // 最大参数数
|
||||||
});
|
// });
|
||||||
factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
// factory.addDeploymentInfoCustomizers(deploymentInfo -> {
|
||||||
|
//
|
||||||
WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
// WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
|
||||||
|
//
|
||||||
// 设置合理的参数
|
// // 设置合理的参数
|
||||||
webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 8192));
|
// webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 8192));
|
||||||
|
//
|
||||||
deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
// deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo);
|
||||||
|
//
|
||||||
// 添加自定义 监控 handler
|
// // 添加自定义 监控 handler
|
||||||
deploymentInfo.addInitialHandlerChainWrapper(next -> new BlockingHandler(customUndertowMetricsHandler.wrap(next)));
|
// deploymentInfo.addInitialHandlerChainWrapper(next -> new BlockingHandler(customUndertowMetricsHandler.wrap(next)));
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
//}
|
|
@ -1,90 +1,88 @@
|
||||||
package org.jeecg.modules.monitor.actuator.undertow;
|
//package org.jeecg.modules.monitor.actuator.undertow;
|
||||||
|
//
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
//import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import io.undertow.server.HttpHandler;
|
//import io.undertow.server.HttpHandler;
|
||||||
import io.undertow.server.HttpServerExchange;
|
//import io.undertow.server.HttpServerExchange;
|
||||||
import io.undertow.server.session.*;
|
//import io.undertow.server.session.*;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
//import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.LongAdder;
|
//import java.util.concurrent.atomic.LongAdder;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 自定义undertow监控指标工具类
|
// * 自定义undertow监控指标工具类
|
||||||
* for [QQYUN-11902]tomcat 替换undertow 这里的功能还没修改
|
// * for [QQYUN-11902]tomcat 替换undertow 这里的功能还没修改
|
||||||
* @author chenrui
|
// * @author chenrui
|
||||||
* @date 2025/4/8 19:06
|
// * @date 2025/4/8 19:06
|
||||||
*/
|
// */
|
||||||
@Component("jeecgCustomUndertowMetricsHandler")
|
//@Component("jeecgCustomUndertowMetricsHandler")
|
||||||
public class CustomUndertowMetricsHandler {
|
//public class CustomUndertowMetricsHandler {
|
||||||
|
//
|
||||||
// 用于统计已创建的 session 数量
|
// // 用于统计已创建的 session 数量
|
||||||
private final LongAdder sessionsCreated = new LongAdder();
|
// private final LongAdder sessionsCreated = new LongAdder();
|
||||||
|
//
|
||||||
// 用于统计已销毁的 session 数量
|
// // 用于统计已销毁的 session 数量
|
||||||
private final LongAdder sessionsExpired = new LongAdder();
|
// private final LongAdder sessionsExpired = new LongAdder();
|
||||||
|
//
|
||||||
// 当前活跃的 session 数量
|
// // 当前活跃的 session 数量
|
||||||
private final AtomicInteger activeSessions = new AtomicInteger();
|
// private final AtomicInteger activeSessions = new AtomicInteger();
|
||||||
|
//
|
||||||
// 历史最大活跃 session 数
|
// // 历史最大活跃 session 数
|
||||||
private final AtomicInteger maxActiveSessions = new AtomicInteger();
|
// private final AtomicInteger maxActiveSessions = new AtomicInteger();
|
||||||
|
//
|
||||||
// Undertow 内存 session 管理器(用于创建与管理 session)
|
// // Undertow 内存 session 管理器(用于创建与管理 session)
|
||||||
private final InMemorySessionManager sessionManager = new InMemorySessionManager("undertow-session-manager");
|
// private final InMemorySessionManager sessionManager = new InMemorySessionManager("undertow-session-manager");
|
||||||
|
//
|
||||||
// 使用 Cookie 存储 session ID
|
// // 使用 Cookie 存储 session ID
|
||||||
private final SessionConfig sessionConfig = new SessionCookieConfig();
|
// private final SessionConfig sessionConfig = new SessionCookieConfig();
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 构造函数
|
// * 构造函数
|
||||||
* @param meterRegistry
|
// * @param meterRegistry
|
||||||
* @author chenrui
|
// * @author chenrui
|
||||||
* @date 2025/4/8 19:07
|
// * @date 2025/4/8 19:07
|
||||||
*/
|
// */
|
||||||
public CustomUndertowMetricsHandler(MeterRegistry meterRegistry) {
|
// public CustomUndertowMetricsHandler(MeterRegistry meterRegistry) {
|
||||||
// 注册 Micrometer 指标
|
// // 注册 Micrometer 指标
|
||||||
meterRegistry.gauge("undertow.sessions.created", sessionsCreated, LongAdder::longValue);
|
// meterRegistry.gauge("undertow.sessions.created", sessionsCreated, LongAdder::longValue);
|
||||||
meterRegistry.gauge("undertow.sessions.expired", sessionsExpired, LongAdder::longValue);
|
// meterRegistry.gauge("undertow.sessions.expired", sessionsExpired, LongAdder::longValue);
|
||||||
meterRegistry.gauge("undertow.sessions.active.current", activeSessions, AtomicInteger::get);
|
// meterRegistry.gauge("undertow.sessions.active.current", activeSessions, AtomicInteger::get);
|
||||||
meterRegistry.gauge("undertow.sessions.active.max", maxActiveSessions, AtomicInteger::get);
|
// meterRegistry.gauge("undertow.sessions.active.max", maxActiveSessions, AtomicInteger::get);
|
||||||
|
//
|
||||||
// 添加 session 生命周期监听器,统计 session 创建与销毁
|
// // 添加 session 生命周期监听器,统计 session 创建与销毁
|
||||||
sessionManager.registerSessionListener(new SessionListener() {
|
// sessionManager.registerSessionListener(new SessionListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void sessionCreated(Session session, HttpServerExchange exchange) {
|
// public void sessionCreated(Session session, HttpServerExchange exchange) {
|
||||||
sessionsCreated.increment();
|
// sessionsCreated.increment();
|
||||||
int now = activeSessions.incrementAndGet();
|
// int now = activeSessions.incrementAndGet();
|
||||||
maxActiveSessions.getAndUpdate(max -> Math.max(max, now));
|
// maxActiveSessions.getAndUpdate(max -> Math.max(max, now));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void sessionDestroyed(Session session, HttpServerExchange exchange, SessionDestroyedReason reason) {
|
// public void sessionDestroyed(Session session, HttpServerExchange exchange, SessionDestroyedReason reason) {
|
||||||
sessionsExpired.increment();
|
// sessionsExpired.increment();
|
||||||
activeSessions.decrementAndGet();
|
// activeSessions.decrementAndGet();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 包装 Undertow 的 HttpHandler,实现 session 自动创建逻辑
|
// * 包装 Undertow 的 HttpHandler,实现 session 自动创建逻辑
|
||||||
* @param next
|
// * @param next
|
||||||
* @return
|
// * @return
|
||||||
* @author chenrui
|
// * @author chenrui
|
||||||
* @date 2025/4/8 19:07
|
// * @date 2025/4/8 19:07
|
||||||
*/
|
// */
|
||||||
public HttpHandler wrap(HttpHandler next) {
|
// public HttpHandler wrap(HttpHandler next) {
|
||||||
return exchange -> {
|
// return exchange -> {
|
||||||
// 获取当前 session,如果不存在则创建
|
// // 获取当前 session,如果不存在则创建
|
||||||
Session session = sessionManager.getSession(exchange, sessionConfig);
|
// Session session = sessionManager.getSession(exchange, sessionConfig);
|
||||||
if (session == null) {
|
// if (session == null) {
|
||||||
try {
|
// sessionManager.createSession(exchange, sessionConfig);
|
||||||
sessionManager.createSession(exchange, sessionConfig);
|
// }
|
||||||
} catch (Exception e) {}
|
//
|
||||||
}
|
// // 执行下一个 Handler
|
||||||
|
// next.handleRequest(exchange);
|
||||||
// 执行下一个 Handler
|
// };
|
||||||
next.handleRequest(exchange);
|
// }
|
||||||
};
|
//}
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue