mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 升级依赖的Spring Boot版本为最新,并优化部分代码
This commit is contained in:
parent
07352d183c
commit
010b43194f
@ -14,7 +14,7 @@
|
|||||||
<description>WxJava 各个模块的 Spring Boot Starter</description>
|
<description>WxJava 各个模块的 Spring Boot Starter</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring.boot.version>2.1.4.RELEASE</spring.boot.version>
|
<spring.boot.version>2.3.3.RELEASE</spring.boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
@ -3,8 +3,6 @@ package me.chanjar.weixin.common.util.locks;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands;
|
import org.springframework.data.redis.connection.RedisStringCommands;
|
||||||
import org.springframework.data.redis.core.RedisCallback;
|
import org.springframework.data.redis.core.RedisCallback;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
@ -76,13 +74,10 @@ public class RedisTemplateSimpleDistributedLock implements Lock {
|
|||||||
}
|
}
|
||||||
final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
|
final byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
|
||||||
final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
|
final byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
|
||||||
List<Object> redisResults = redisTemplate.executePipelined(new RedisCallback<String>() {
|
List<Object> redisResults = redisTemplate.executePipelined((RedisCallback<String>) connection -> {
|
||||||
@Override
|
|
||||||
public String doInRedis(RedisConnection connection) throws DataAccessException {
|
|
||||||
connection.set(keyBytes, valueBytes, Expiration.milliseconds(leaseMilliseconds), RedisStringCommands.SetOption.SET_IF_ABSENT);
|
connection.set(keyBytes, valueBytes, Expiration.milliseconds(leaseMilliseconds), RedisStringCommands.SetOption.SET_IF_ABSENT);
|
||||||
connection.get(keyBytes);
|
connection.get(keyBytes);
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Object currentLockSecret = redisResults.size() > 1 ? redisResults.get(1) : redisResults.get(0);
|
Object currentLockSecret = redisResults.size() > 1 ? redisResults.get(1) : redisResults.get(0);
|
||||||
return currentLockSecret != null && currentLockSecret.toString().equals(value);
|
return currentLockSecret != null && currentLockSecret.toString().equals(value);
|
||||||
|
@ -1,18 +1,5 @@
|
|||||||
package me.chanjar.weixin.mp.api;
|
package me.chanjar.weixin.mp.api;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
|
import me.chanjar.weixin.common.api.WxErrorExceptionHandler;
|
||||||
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
|
import me.chanjar.weixin.common.api.WxMessageDuplicateChecker;
|
||||||
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
|
import me.chanjar.weixin.common.api.WxMessageInMemoryDuplicateChecker;
|
||||||
@ -23,6 +10,18 @@ import me.chanjar.weixin.common.session.WxSessionManager;
|
|||||||
import me.chanjar.weixin.common.util.LogExceptionHandler;
|
import me.chanjar.weixin.common.util.LogExceptionHandler;
|
||||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
||||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
@ -183,7 +182,7 @@ public class WxMpMessageRouter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchRules.size() == 0) {
|
if (matchRules.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +192,8 @@ public class WxMpMessageRouter {
|
|||||||
// 返回最后一个非异步的rule的执行结果
|
// 返回最后一个非异步的rule的执行结果
|
||||||
if (rule.isAsync()) {
|
if (rule.isAsync()) {
|
||||||
futures.add(
|
futures.add(
|
||||||
this.executorService.submit(new Runnable() {
|
this.executorService.submit(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
rule.service(wxMessage, context, mpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
|
rule.service(wxMessage, context, mpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -208,10 +204,11 @@ public class WxMpMessageRouter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (futures.size() > 0) {
|
if (futures.isEmpty()) {
|
||||||
this.executorService.submit(new Runnable() {
|
return res;
|
||||||
@Override
|
}
|
||||||
public void run() {
|
|
||||||
|
this.executorService.submit(() -> {
|
||||||
for (Future<?> future : futures) {
|
for (Future<?> future : futures) {
|
||||||
try {
|
try {
|
||||||
future.get();
|
future.get();
|
||||||
@ -225,18 +222,16 @@ public class WxMpMessageRouter {
|
|||||||
WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
|
WxMpMessageRouter.this.log.error("Error happened when wait task finish", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
|
public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
|
||||||
return this.route(wxMessage, new HashMap<String, Object>(2));
|
return this.route(wxMessage, new HashMap<>(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public WxMpXmlOutMessage route(String appid, final WxMpXmlMessage wxMessage) {
|
public WxMpXmlOutMessage route(String appid, final WxMpXmlMessage wxMessage) {
|
||||||
return this.route(appid, wxMessage, new HashMap<String, Object>(2));
|
return this.route(appid, wxMessage, new HashMap<>(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {
|
private boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user