nginx 配置如下
upstream crserver {
#ip_hash;
server 127.0.0.1:8090;
server 127.0.0.1:8091;
}
代码:
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
/* Config config = new Config();
config.useSingleServer()
.setAddress("redis://127.0.0.1:6379");
RedissonClient redissonClient = Redisson.create(config);
String resourceName="REDLOCK_KEY";
RLock lock= redissonClient.getLock(resourceName);
RedissonRedLock redLock = new RedissonRedLock(lock);
boolean isLock;
try { // isLock = redLock.tryLock(); // 500ms拿不到锁, 就认为获取锁失败。10000ms即10s是锁失效时间。
isLock = redLock.tryLock(500, 10000, TimeUnit.MILLISECONDS);
log.info("lock is "+isLock);
if (isLock) {
log.info("JWTFilter doFilterInternal :time:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd hh:mm:ss"));
//从url中根据参数获取值
String jwt = obtainParameter(request, GlobalConstant.jwt);
Authentication authentication=null;
if (StringUtils.hasText(jwt)) {
getAuthentication( jwt ,response);
}
filterChain.doFilter(request, response);
}
} catch (Exception e) {
log.error(e.getMessage());
} finally {
redLock.unlock();
}*/
log.info("JWTFilter doFilterInternal :time:"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd hh:mm:ss"));
//从url中根据参数获取值
String jwt = obtainParameter(request, GlobalConstant.jwt);
Authentication authentication=null;
if (StringUtils.hasText(jwt)) {
getAuthentication( jwt ,response);
}
filterChain.doFilter(request, response);
}
8091机器日志:
2021-06-23 10:35:07.626 INFO 16892 --- [nio-8091-exec-1] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.665 INFO 16892 --- [nio-8091-exec-2] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.675 INFO 16892 --- [nio-8091-exec-3] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.683 INFO 16892 --- [nio-8091-exec-4] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.692 INFO 16892 --- [nio-8091-exec-5] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
8090机器日志:
2021-06-23 10:35:07.550 INFO 13580 --- [nio-8090-exec-1] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.637 INFO 13580 --- [nio-8090-exec-2] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.670 INFO 13580 --- [nio-8090-exec-3] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.679 INFO 13580 --- [nio-8090-exec-4] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.687 INFO 13580 --- [nio-8090-exec-5] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
2021-06-23 10:35:07.696 INFO 13580 --- [nio-8090-exec-6] c.e.d.config.security.filter.JWTFilter : JWTFilter doFilterInternal :time:2021-06-23 10:35:07
问题:
为什么在doFilter这里相互调用导致没有进入登录逻辑
把这个redis 锁去掉看看
测试的时候,已经注释去掉了和这个没有关系的。