From 0a5fdf63498278e7236c17d85b21eca4972c713f Mon Sep 17 00:00:00 2001 From: lpphan <@163.com> Date: Thu, 17 Mar 2022 23:10:35 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E8=BF=87=E6=9C=9Fkey=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/store/CustomRedisTokenStore.java | 16 ++- .../common/constant/SecurityConstants.java | 4 + .../redis/template/RedisRepository.java | 22 ++++ .../oauth/config/RedisListenerConfig.java | 24 ++++ .../listener/RedisKeyExpirationListener.java | 111 ++++++++++++++++++ 5 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java create mode 100644 zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java index ad35a6ff..f07ddb0d 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/CustomRedisTokenStore.java @@ -39,6 +39,7 @@ */ public class CustomRedisTokenStore implements TokenStore { private static final String ACCESS = "access:"; + private static final String ACCESS_BAK = "access_bak:"; private static final String AUTH_TO_ACCESS = "auth_to_access:"; private static final String REFRESH_AUTH = "refresh_auth:"; private static final String ACCESS_TO_REFRESH = "access_to_refresh:"; @@ -118,7 +119,7 @@ private OAuth2RefreshToken deserializeRefreshToken(byte[] bytes) { } private ClientDetails deserializeClientDetails(byte[] bytes) { - return (ClientDetails)redisValueSerializer.deserialize(bytes); + return (ClientDetails) redisValueSerializer.deserialize(bytes); } private byte[] serialize(String string) { @@ -166,7 +167,7 @@ public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { //获取过期时长 int validitySeconds = getAccessTokenValiditySeconds(clientAuth.getClientId()); if (validitySeconds > 0) { - double expiresRatio = token.getExpiresIn() / (double)validitySeconds; + double expiresRatio = token.getExpiresIn() / (double) validitySeconds; //判断是否需要续签,当前剩余时间小于过期时长的50%则续签 if (expiresRatio <= securityProperties.getAuth().getRenew().getTimeRatio()) { //更新AccessToken过期时间 @@ -182,6 +183,7 @@ public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { /** * 判断应用自动续签是否满足白名单和黑名单的过滤逻辑 + * * @param clientId 应用id * @return 是否满足 */ @@ -193,7 +195,7 @@ private boolean checkRenewClientId(String clientId) { List exclusiveClientIds = securityProperties.getAuth().getRenew().getExclusiveClientIds(); if (includeClientIds.size() > 0) { result = includeClientIds.contains(clientId); - } else if(exclusiveClientIds.size() > 0) { + } else if (exclusiveClientIds.size() > 0) { result = !exclusiveClientIds.contains(clientId); } return result; @@ -201,6 +203,7 @@ private boolean checkRenewClientId(String clientId) { /** * 获取token的总有效时长 + * * @param clientId 应用id */ private int getAccessTokenValiditySeconds(String clientId) { @@ -256,12 +259,14 @@ public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authe /** * 存储token + * * @param isRenew 是否续签 */ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication, boolean isRenew) { byte[] serializedAccessToken = serialize(token); byte[] serializedAuth = serialize(authentication); byte[] accessKey = serializeKey(ACCESS + token.getValue()); + byte[] accessBakKey = serializeKey(ACCESS_BAK + token.getValue()); byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + token.getValue()); byte[] authToAccessKey = serializeKey(AUTH_TO_ACCESS + authenticationKeyGenerator.extractKey(authentication)); byte[] approvalKey = serializeKey(SecurityConstants.REDIS_UNAME_TO_ACCESS + getApprovalKey(authentication)); @@ -279,6 +284,7 @@ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication auth if (springDataRedis_2_0) { try { this.redisConnectionSet_2_0.invoke(conn, accessKey, serializedAccessToken); + this.redisConnectionSet_2_0.invoke(conn, accessBakKey, serializedAccessToken); this.redisConnectionSet_2_0.invoke(conn, authKey, serializedAuth); this.redisConnectionSet_2_0.invoke(conn, authToAccessKey, serializedAccessToken); } catch (Exception ex) { @@ -286,6 +292,7 @@ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication auth } } else { conn.set(accessKey, serializedAccessToken); + conn.set(accessBakKey, serializedAccessToken); conn.set(authKey, serializedAuth); conn.set(authToAccessKey, serializedAccessToken); } @@ -303,6 +310,7 @@ private void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication auth if (token.getExpiration() != null) { int seconds = token.getExpiresIn(); conn.expire(accessKey, seconds); + conn.expire(accessBakKey, seconds + 60); conn.expire(authKey, seconds); conn.expire(authToAccessKey, seconds); conn.expire(clientId, seconds); @@ -363,6 +371,7 @@ public OAuth2AccessToken readAccessToken(String tokenValue) { public void removeAccessToken(String tokenValue) { byte[] accessKey = serializeKey(ACCESS + tokenValue); + byte[] accessBakKey = serializeKey(ACCESS_BAK + tokenValue); byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + tokenValue); byte[] accessToRefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue); RedisConnection conn = getConnection(); @@ -371,6 +380,7 @@ public void removeAccessToken(String tokenValue) { byte[] auth = conn.get(authKey); conn.openPipeline(); conn.del(accessKey); + conn.del(accessBakKey); conn.del(accessToRefreshKey); // Don't remove the refresh token - it's up to the caller to do that conn.del(authKey); diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/SecurityConstants.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/SecurityConstants.java index 45f0c129..4cca9640 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/SecurityConstants.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/SecurityConstants.java @@ -154,6 +154,10 @@ public interface SecurityConstants { * redis中授权token对应的key */ String REDIS_TOKEN_AUTH = "auth:"; + /** + * 值同access 过期时间+60 + */ + String ACCESS_BAK = "access_bak:"; /** * redis中应用对应的token集合的key */ diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java index d6c1162d..d73cfcac 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java @@ -1,6 +1,7 @@ package com.central.common.redis.template; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisConnection; @@ -178,6 +179,26 @@ public byte[] get(final byte[] key) { public Object get(final String key) { return redisTemplate.opsForValue().get(key); } + + /** + *获取原来key键对应的值并重新赋新值。 + * @param key + * @param value + * @return + */ + public String getAndSet(final String key,Object value) { + String result = null; + if (StringUtils.isEmpty(key)){ + log.error("key不能为空"); + return null; + } + try { + result = (String) redisTemplate.opsForValue().getAndSet(key, value); + }catch (Exception e){ + e.printStackTrace(); + } + return result; + } /** * 根据key获取对象 * @@ -190,6 +211,7 @@ public Object get(final String key, RedisSerializer valueSerializer) { return redisTemplate.execute(connection -> deserializeValue(connection.get(rawKey), valueSerializer), true); } + /** * Ops for hash hash operations. * diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java new file mode 100644 index 00000000..3cfe01cb --- /dev/null +++ b/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java @@ -0,0 +1,24 @@ +package com.central.oauth.config; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +/** + * + * redis过期key监听器配置类 + * @author zlt + * + */ +@Configuration +public class RedisListenerConfig { + @Bean + @Primary + public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) { + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + container.setConnectionFactory(connectionFactory); + return container; + } +} diff --git a/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java new file mode 100644 index 00000000..b4a49130 --- /dev/null +++ b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java @@ -0,0 +1,111 @@ +package com.central.oauth.listener; + +import com.central.common.constant.SecurityConstants; +import com.central.common.redis.template.RedisRepository; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.connection.Message; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.provider.token.store.redis.JdkSerializationStrategy; +import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStoreSerializationStrategy; +import org.springframework.stereotype.Component; + +/** + * + * redis过期key监听器 + * @author zlt + * + */ +@Component +@Slf4j +public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener { + @Autowired + private RedisRepository redisRepository; + private RedisTokenStoreSerializationStrategy serializationStrategy = new JdkSerializationStrategy(); + private final RedisConnectionFactory connectionFactory; + + public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer, RedisConnectionFactory connectionFactory) { + super(listenerContainer); + this.connectionFactory = connectionFactory; + } + + @Override + public void onMessage(Message message, byte[] pattern) { + if (message == null) { + log.debug("message不能为空"); + return; + } + //获取失效的的key + String expiredKey = message.toString(); + if (StringUtils.isEmpty(expiredKey)) { + log.debug("expiredKey不能为空"); + return; + } + String accesskey = expiredKey.substring(0, expiredKey.indexOf(":") + 1); + if (!"access:".equals(accesskey)) { + log.debug("非需要监听key,跳过"); + return; + } + String accessValue = expiredKey.substring(expiredKey.indexOf(":") + 1); + // 分布式集群部署下防止一个过期被多个服务重复消费 + String qc = redisRepository.getAndSet("qc:" + accessValue, "1"); + if (StringUtils.isNotEmpty(qc) && "1".equals(qc)) { + log.debug("其他节点已经处理了该数据,次数跳过"); + return; + } + byte[] accessBakKey = serializeKey(SecurityConstants.ACCESS_BAK + accessValue); + byte[] authKey = serializeKey(SecurityConstants.REDIS_TOKEN_AUTH + accessValue); + RedisConnection conn = getConnection(); + try { + byte[] access = conn.get(accessBakKey); + byte[] auth = conn.get(authKey); + OAuth2Authentication authentication = deserializeAuthentication(auth); + if (authentication != null) { + byte[] unameKey = serializeKey(SecurityConstants.REDIS_UNAME_TO_ACCESS + getApprovalKey(authentication)); + byte[] clientId = serializeKey(SecurityConstants.REDIS_CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId()); + conn.openPipeline(); + conn.lRem(unameKey, 1, access); + conn.lRem(clientId, 1, access); + conn.closePipeline(); + } + } catch (Exception e) { + log.error(e.getMessage()); + } finally { + conn.del(); + conn.close(); + } + + } + + private byte[] serializeKey(String object) { + return serialize("" + object); + } + + private byte[] serialize(String string) { + return serializationStrategy.serialize(string); + } + + private RedisConnection getConnection() { + return connectionFactory.getConnection(); + } + + private OAuth2Authentication deserializeAuthentication(byte[] bytes) { + return serializationStrategy.deserialize(bytes, OAuth2Authentication.class); + } + + private static String getApprovalKey(OAuth2Authentication authentication) { + String userName = authentication.getUserAuthentication() == null ? "" + : authentication.getUserAuthentication().getName(); + return getApprovalKey(authentication.getOAuth2Request().getClientId(), userName); + } + + private static String getApprovalKey(String clientId, String userName) { + return clientId + (userName == null ? "" : ":" + userName); + } +} From 05a65721be0844a9153c3d9d39e26eda56ab28ba Mon Sep 17 00:00:00 2001 From: lpphan <@163.com> Date: Fri, 18 Mar 2022 10:25:21 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/template/RedisRepository.java | 993 +++++++++--------- .../oauth/config/RedisListenerConfig.java | 4 +- .../listener/RedisKeyExpirationListener.java | 9 +- 3 files changed, 505 insertions(+), 501 deletions(-) diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java index d73cfcac..7c80302f 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java +++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/template/RedisRepository.java @@ -1,495 +1,498 @@ -package com.central.common.redis.template; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.dao.DataAccessException; -import org.springframework.data.redis.connection.RedisClusterNode; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.RedisServerCommands; -import org.springframework.data.redis.core.*; -import org.springframework.data.redis.serializer.RedisSerializer; -import org.springframework.data.redis.serializer.SerializationUtils; -import org.springframework.util.Assert; - -import java.util.*; -import java.util.concurrent.TimeUnit; - -/** - * Redis Repository - * redis 基本操作 可扩展,基本够用了 - * - * @author zlt - *

- * Blog: https://zlt2000.gitee.io - * Github: https://github.com/zlt2000 - */ -@Slf4j -public class RedisRepository { - /** - * Spring Redis Template - */ - private RedisTemplate redisTemplate; - - public RedisRepository(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - - /** - * 获取链接工厂 - */ - public RedisConnectionFactory getConnectionFactory() { - return this.redisTemplate.getConnectionFactory(); - } - - /** - * 获取 RedisTemplate对象 - */ - public RedisTemplate getRedisTemplate() { - return redisTemplate; - } - - /** - * 清空DB - * - * @param node redis 节点 - */ - public void flushDB(RedisClusterNode node) { - this.redisTemplate.opsForCluster().flushDb(node); - } - - /** - * 添加到带有 过期时间的 缓存 - * - * @param key redis主键 - * @param value 值 - * @param time 过期时间(单位秒) - */ - public void setExpire(final byte[] key, final byte[] value, final long time) { - redisTemplate.execute((RedisCallback) connection -> { - connection.setEx(key, time, value); - return 1L; - }); - } - - /** - * 添加到带有 过期时间的 缓存 - * - * @param key redis主键 - * @param value 值 - * @param time 过期时间 - * @param timeUnit 过期时间单位 - */ - public void setExpire(final String key, final Object value, final long time, final TimeUnit timeUnit) { - redisTemplate.opsForValue().set(key, value, time, timeUnit); - } - public void setExpire(final String key, final Object value, final long time) { - this.setExpire(key, value, time, TimeUnit.SECONDS); - } - public void setExpire(final String key, final Object value, final long time, final TimeUnit timeUnit, RedisSerializer valueSerializer) { - byte[] rawKey = rawKey(key); - byte[] rawValue = rawValue(value, valueSerializer); - - redisTemplate.execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) throws DataAccessException { - potentiallyUsePsetEx(connection); - return null; - } - public void potentiallyUsePsetEx(RedisConnection connection) { - if (!TimeUnit.MILLISECONDS.equals(timeUnit) || !failsafeInvokePsetEx(connection)) { - connection.setEx(rawKey, TimeoutUtils.toSeconds(time, timeUnit), rawValue); - } - } - private boolean failsafeInvokePsetEx(RedisConnection connection) { - boolean failed = false; - try { - connection.pSetEx(rawKey, time, rawValue); - } catch (UnsupportedOperationException e) { - failed = true; - } - return !failed; - } - }, true); - } - - /** - * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销 - * - * @param keys redis主键数组 - * @param values 值数组 - * @param time 过期时间(单位秒) - */ - public void setExpire(final String[] keys, final Object[] values, final long time) { - for (int i = 0; i < keys.length; i++) { - redisTemplate.opsForValue().set(keys[i], values[i], time, TimeUnit.SECONDS); - } - } - - - /** - * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销 - * - * @param keys the keys - * @param values the values - */ - public void set(final String[] keys, final Object[] values) { - for (int i = 0; i < keys.length; i++) { - redisTemplate.opsForValue().set(keys[i], values[i]); - } - } - - - /** - * 添加到缓存 - * - * @param key the key - * @param value the value - */ - public void set(final String key, final Object value) { - redisTemplate.opsForValue().set(key, value); - } - - /** - * 查询在以keyPatten的所有 key - * - * @param keyPatten the key patten - * @return the set - */ - public Set keys(final String keyPatten) { - return redisTemplate.keys(keyPatten + "*"); - } - - /** - * 根据key获取对象 - * - * @param key the key - * @return the byte [ ] - */ - public byte[] get(final byte[] key) { - return redisTemplate.execute((RedisCallback) connection -> connection.get(key)); - } - - /** - * 根据key获取对象 - * - * @param key the key - * @return the string - */ - public Object get(final String key) { - return redisTemplate.opsForValue().get(key); - } - - /** - *获取原来key键对应的值并重新赋新值。 - * @param key - * @param value - * @return - */ - public String getAndSet(final String key,Object value) { - String result = null; - if (StringUtils.isEmpty(key)){ - log.error("key不能为空"); - return null; - } - try { - result = (String) redisTemplate.opsForValue().getAndSet(key, value); - }catch (Exception e){ - e.printStackTrace(); - } - return result; - } - /** - * 根据key获取对象 - * - * @param key the key - * @param valueSerializer 序列化 - * @return the string - */ - public Object get(final String key, RedisSerializer valueSerializer) { - byte[] rawKey = rawKey(key); - return redisTemplate.execute(connection -> deserializeValue(connection.get(rawKey), valueSerializer), true); - } - - - /** - * Ops for hash hash operations. - * - * @return the hash operations - */ - public HashOperations opsForHash() { - return redisTemplate.opsForHash(); - } - - /** - * 对HashMap操作 - * - * @param key the key - * @param hashKey the hash key - * @param hashValue the hash value - */ - public void putHashValue(String key, String hashKey, Object hashValue) { - opsForHash().put(key, hashKey, hashValue); - } - - /** - * 获取单个field对应的值 - * - * @param key the key - * @param hashKey the hash key - * @return the hash values - */ - public Object getHashValues(String key, String hashKey) { - return opsForHash().get(key, hashKey); - } - - /** - * 根据key值删除 - * - * @param key the key - * @param hashKeys the hash keys - */ - public void delHashValues(String key, Object... hashKeys) { - opsForHash().delete(key, hashKeys); - } - - /** - * key只匹配map - * - * @param key the key - * @return the hash value - */ - public Map getHashValue(String key) { - return opsForHash().entries(key); - } - - /** - * 批量添加 - * - * @param key the key - * @param map the map - */ - public void putHashValues(String key, Map map) { - opsForHash().putAll(key, map); - } - - /** - * 集合数量 - * - * @return the long - */ - public long dbSize() { - return redisTemplate.execute(RedisServerCommands::dbSize); - } - - /** - * 清空redis存储的数据 - * - * @return the string - */ - public String flushDB() { - return redisTemplate.execute((RedisCallback) connection -> { - connection.flushDb(); - return "ok"; - }); - } - - /** - * 判断某个主键是否存在 - * - * @param key the key - * @return the boolean - */ - public boolean exists(final String key) { - return redisTemplate.hasKey(key); - } - - - /** - * 删除key - * - * @param keys the keys - * @return the long - */ - public boolean del(final String... keys) { - boolean result = false; - for (String key : keys) { - result = redisTemplate.delete(key); - } - return result; - } - - /** - * 对某个主键对应的值加一,value值必须是全数字的字符串 - * - * @param key the key - * @return the long - */ - public long incr(final String key) { - return redisTemplate.opsForValue().increment(key); - } - - /** - * redis List 引擎 - * - * @return the list operations - */ - public ListOperations opsForList() { - return redisTemplate.opsForList(); - } - - /** - * redis List数据结构 : 将一个或多个值 value 插入到列表 key 的表头 - * - * @param key the key - * @param value the value - * @return the long - */ - public Long leftPush(String key, Object value) { - return opsForList().leftPush(key, value); - } - - /** - * redis List数据结构 : 移除并返回列表 key 的头元素 - * - * @param key the key - * @return the string - */ - public Object leftPop(String key) { - return opsForList().leftPop(key); - } - - /** - * redis List数据结构 :将一个或多个值 value 插入到列表 key 的表尾(最右边)。 - * - * @param key the key - * @param value the value - * @return the long - */ - public Long in(String key, Object value) { - return opsForList().rightPush(key, value); - } - - /** - * redis List数据结构 : 移除并返回列表 key 的末尾元素 - * - * @param key the key - * @return the string - */ - public Object rightPop(String key) { - return opsForList().rightPop(key); - } - - - /** - * redis List数据结构 : 返回列表 key 的长度 ; 如果 key 不存在,则 key 被解释为一个空列表,返回 0 ; 如果 key 不是列表类型,返回一个错误。 - * - * @param key the key - * @return the long - */ - public Long length(String key) { - return opsForList().size(key); - } - - - /** - * redis List数据结构 : 根据参数 i 的值,移除列表中与参数 value 相等的元素 - * - * @param key the key - * @param i the - * @param value the value - */ - public void remove(String key, long i, Object value) { - opsForList().remove(key, i, value); - } - - /** - * redis List数据结构 : 将列表 key 下标为 index 的元素的值设置为 value - * - * @param key the key - * @param index the index - * @param value the value - */ - public void set(String key, long index, Object value) { - opsForList().set(key, index, value); - } - - /** - * redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。 - * - * @param key the key - * @param start the start - * @param end the end - * @return the list - */ - public List getList(String key, int start, int end) { - return opsForList().range(key, start, end); - } - - /** - * redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。 - * - * @param key the key - * @param start the start - * @param end the end - * @param valueSerializer 序列化 - * @return the list - */ - public List getList(String key, int start, int end, RedisSerializer valueSerializer) { - byte[] rawKey = rawKey(key); - return redisTemplate.execute(connection -> deserializeValues(connection.lRange(rawKey, start, end), valueSerializer), true); - } - - /** - * redis List数据结构 : 批量存储 - * - * @param key the key - * @param list the list - * @return the long - */ - public Long leftPushAll(String key, List list) { - return opsForList().leftPushAll(key, list); - } - - /** - * redis List数据结构 : 将值 value 插入到列表 key 当中,位于值 index 之前或之后,默认之后。 - * - * @param key the key - * @param index the index - * @param value the value - */ - public void insert(String key, long index, Object value) { - opsForList().set(key, index, value); - } - - private byte[] rawKey(Object key) { - Assert.notNull(key, "non null key required"); - - if (key instanceof byte[]) { - return (byte[]) key; - } - RedisSerializer redisSerializer = (RedisSerializer)redisTemplate.getKeySerializer(); - return redisSerializer.serialize(key); - } - private byte[] rawValue(Object value, RedisSerializer valueSerializer) { - if (value instanceof byte[]) { - return (byte[]) value; - } - - return valueSerializer.serialize(value); - } - - private List deserializeValues(List rawValues, RedisSerializer valueSerializer) { - if (valueSerializer == null) { - return rawValues; - } - return SerializationUtils.deserialize(rawValues, valueSerializer); - } - - private Object deserializeValue(byte[] value, RedisSerializer valueSerializer) { - if (valueSerializer == null) { - return value; - } - return valueSerializer.deserialize(value); - } -} +package com.central.common.redis.template; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.dao.DataAccessException; +import org.springframework.data.redis.connection.RedisClusterNode; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisServerCommands; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationUtils; +import org.springframework.util.Assert; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Redis Repository + * redis 基本操作 可扩展,基本够用了 + * + * @author zlt + *

+ * Blog: https://zlt2000.gitee.io + * Github: https://github.com/zlt2000 + */ +@Slf4j +public class RedisRepository { + /** + * Spring Redis Template + */ + private RedisTemplate redisTemplate; + + public RedisRepository(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + /** + * 获取链接工厂 + */ + public RedisConnectionFactory getConnectionFactory() { + return this.redisTemplate.getConnectionFactory(); + } + + /** + * 获取 RedisTemplate对象 + */ + public RedisTemplate getRedisTemplate() { + return redisTemplate; + } + + /** + * 清空DB + * + * @param node redis 节点 + */ + public void flushDB(RedisClusterNode node) { + this.redisTemplate.opsForCluster().flushDb(node); + } + + /** + * 添加到带有 过期时间的 缓存 + * + * @param key redis主键 + * @param value 值 + * @param time 过期时间(单位秒) + */ + public void setExpire(final byte[] key, final byte[] value, final long time) { + redisTemplate.execute((RedisCallback) connection -> { + connection.setEx(key, time, value); + return 1L; + }); + } + + /** + * 添加到带有 过期时间的 缓存 + * + * @param key redis主键 + * @param value 值 + * @param time 过期时间 + * @param timeUnit 过期时间单位 + */ + public void setExpire(final String key, final Object value, final long time, final TimeUnit timeUnit) { + redisTemplate.opsForValue().set(key, value, time, timeUnit); + } + public void setExpire(final String key, final Object value, final long time) { + this.setExpire(key, value, time, TimeUnit.SECONDS); + } + public void setExpire(final String key, final Object value, final long time, final TimeUnit timeUnit, RedisSerializer valueSerializer) { + byte[] rawKey = rawKey(key); + byte[] rawValue = rawValue(value, valueSerializer); + + redisTemplate.execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + potentiallyUsePsetEx(connection); + return null; + } + public void potentiallyUsePsetEx(RedisConnection connection) { + if (!TimeUnit.MILLISECONDS.equals(timeUnit) || !failsafeInvokePsetEx(connection)) { + connection.setEx(rawKey, TimeoutUtils.toSeconds(time, timeUnit), rawValue); + } + } + private boolean failsafeInvokePsetEx(RedisConnection connection) { + boolean failed = false; + try { + connection.pSetEx(rawKey, time, rawValue); + } catch (UnsupportedOperationException e) { + failed = true; + } + return !failed; + } + }, true); + } + + /** + * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销 + * + * @param keys redis主键数组 + * @param values 值数组 + * @param time 过期时间(单位秒) + */ + public void setExpire(final String[] keys, final Object[] values, final long time) { + for (int i = 0; i < keys.length; i++) { + redisTemplate.opsForValue().set(keys[i], values[i], time, TimeUnit.SECONDS); + } + } + + + /** + * 一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销 + * + * @param keys the keys + * @param values the values + */ + public void set(final String[] keys, final Object[] values) { + for (int i = 0; i < keys.length; i++) { + redisTemplate.opsForValue().set(keys[i], values[i]); + } + } + + + /** + * 添加到缓存 + * + * @param key the key + * @param value the value + */ + public void set(final String key, final Object value) { + redisTemplate.opsForValue().set(key, value); + } + + /** + * 查询在以keyPatten的所有 key + * + * @param keyPatten the key patten + * @return the set + */ + public Set keys(final String keyPatten) { + return redisTemplate.keys(keyPatten + "*"); + } + + /** + * 根据key获取对象 + * + * @param key the key + * @return the byte [ ] + */ + public byte[] get(final byte[] key) { + return redisTemplate.execute((RedisCallback) connection -> connection.get(key)); + } + + /** + * 根据key获取对象 + * + * @param key the key + * @return the string + */ + public Object get(final String key) { + return redisTemplate.opsForValue().get(key); + } + + /** + *获取原来key键对应的值并重新赋新值。 + * @param key + * @param value + * @return + */ + public String getAndSet(final String key,String value) { + String result = null; + if (StringUtils.isEmpty(key)){ + log.error("非法入参"); + return null; + } + try { + Object object =redisTemplate.opsForValue().getAndSet(key, value); + if (object !=null){ + result = object.toString(); + } + }catch (Exception e){ + log.error("redisTemplate操作异常",e); + } + return result; + } + /** + * 根据key获取对象 + * + * @param key the key + * @param valueSerializer 序列化 + * @return the string + */ + public Object get(final String key, RedisSerializer valueSerializer) { + byte[] rawKey = rawKey(key); + return redisTemplate.execute(connection -> deserializeValue(connection.get(rawKey), valueSerializer), true); + } + + + /** + * Ops for hash hash operations. + * + * @return the hash operations + */ + public HashOperations opsForHash() { + return redisTemplate.opsForHash(); + } + + /** + * 对HashMap操作 + * + * @param key the key + * @param hashKey the hash key + * @param hashValue the hash value + */ + public void putHashValue(String key, String hashKey, Object hashValue) { + opsForHash().put(key, hashKey, hashValue); + } + + /** + * 获取单个field对应的值 + * + * @param key the key + * @param hashKey the hash key + * @return the hash values + */ + public Object getHashValues(String key, String hashKey) { + return opsForHash().get(key, hashKey); + } + + /** + * 根据key值删除 + * + * @param key the key + * @param hashKeys the hash keys + */ + public void delHashValues(String key, Object... hashKeys) { + opsForHash().delete(key, hashKeys); + } + + /** + * key只匹配map + * + * @param key the key + * @return the hash value + */ + public Map getHashValue(String key) { + return opsForHash().entries(key); + } + + /** + * 批量添加 + * + * @param key the key + * @param map the map + */ + public void putHashValues(String key, Map map) { + opsForHash().putAll(key, map); + } + + /** + * 集合数量 + * + * @return the long + */ + public long dbSize() { + return redisTemplate.execute(RedisServerCommands::dbSize); + } + + /** + * 清空redis存储的数据 + * + * @return the string + */ + public String flushDB() { + return redisTemplate.execute((RedisCallback) connection -> { + connection.flushDb(); + return "ok"; + }); + } + + /** + * 判断某个主键是否存在 + * + * @param key the key + * @return the boolean + */ + public boolean exists(final String key) { + return redisTemplate.hasKey(key); + } + + + /** + * 删除key + * + * @param keys the keys + * @return the long + */ + public boolean del(final String... keys) { + boolean result = false; + for (String key : keys) { + result = redisTemplate.delete(key); + } + return result; + } + + /** + * 对某个主键对应的值加一,value值必须是全数字的字符串 + * + * @param key the key + * @return the long + */ + public long incr(final String key) { + return redisTemplate.opsForValue().increment(key); + } + + /** + * redis List 引擎 + * + * @return the list operations + */ + public ListOperations opsForList() { + return redisTemplate.opsForList(); + } + + /** + * redis List数据结构 : 将一个或多个值 value 插入到列表 key 的表头 + * + * @param key the key + * @param value the value + * @return the long + */ + public Long leftPush(String key, Object value) { + return opsForList().leftPush(key, value); + } + + /** + * redis List数据结构 : 移除并返回列表 key 的头元素 + * + * @param key the key + * @return the string + */ + public Object leftPop(String key) { + return opsForList().leftPop(key); + } + + /** + * redis List数据结构 :将一个或多个值 value 插入到列表 key 的表尾(最右边)。 + * + * @param key the key + * @param value the value + * @return the long + */ + public Long in(String key, Object value) { + return opsForList().rightPush(key, value); + } + + /** + * redis List数据结构 : 移除并返回列表 key 的末尾元素 + * + * @param key the key + * @return the string + */ + public Object rightPop(String key) { + return opsForList().rightPop(key); + } + + + /** + * redis List数据结构 : 返回列表 key 的长度 ; 如果 key 不存在,则 key 被解释为一个空列表,返回 0 ; 如果 key 不是列表类型,返回一个错误。 + * + * @param key the key + * @return the long + */ + public Long length(String key) { + return opsForList().size(key); + } + + + /** + * redis List数据结构 : 根据参数 i 的值,移除列表中与参数 value 相等的元素 + * + * @param key the key + * @param i the + * @param value the value + */ + public void remove(String key, long i, Object value) { + opsForList().remove(key, i, value); + } + + /** + * redis List数据结构 : 将列表 key 下标为 index 的元素的值设置为 value + * + * @param key the key + * @param index the index + * @param value the value + */ + public void set(String key, long index, Object value) { + opsForList().set(key, index, value); + } + + /** + * redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。 + * + * @param key the key + * @param start the start + * @param end the end + * @return the list + */ + public List getList(String key, int start, int end) { + return opsForList().range(key, start, end); + } + + /** + * redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 end 指定。 + * + * @param key the key + * @param start the start + * @param end the end + * @param valueSerializer 序列化 + * @return the list + */ + public List getList(String key, int start, int end, RedisSerializer valueSerializer) { + byte[] rawKey = rawKey(key); + return redisTemplate.execute(connection -> deserializeValues(connection.lRange(rawKey, start, end), valueSerializer), true); + } + + /** + * redis List数据结构 : 批量存储 + * + * @param key the key + * @param list the list + * @return the long + */ + public Long leftPushAll(String key, List list) { + return opsForList().leftPushAll(key, list); + } + + /** + * redis List数据结构 : 将值 value 插入到列表 key 当中,位于值 index 之前或之后,默认之后。 + * + * @param key the key + * @param index the index + * @param value the value + */ + public void insert(String key, long index, Object value) { + opsForList().set(key, index, value); + } + + private byte[] rawKey(Object key) { + Assert.notNull(key, "non null key required"); + + if (key instanceof byte[]) { + return (byte[]) key; + } + RedisSerializer redisSerializer = (RedisSerializer)redisTemplate.getKeySerializer(); + return redisSerializer.serialize(key); + } + private byte[] rawValue(Object value, RedisSerializer valueSerializer) { + if (value instanceof byte[]) { + return (byte[]) value; + } + + return valueSerializer.serialize(value); + } + + private List deserializeValues(List rawValues, RedisSerializer valueSerializer) { + if (valueSerializer == null) { + return rawValues; + } + return SerializationUtils.deserialize(rawValues, valueSerializer); + } + + private Object deserializeValue(byte[] value, RedisSerializer valueSerializer) { + if (valueSerializer == null) { + return value; + } + return valueSerializer.deserialize(value); + } +} diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java index 3cfe01cb..68f98f8f 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java +++ b/zlt-uaa/src/main/java/com/central/oauth/config/RedisListenerConfig.java @@ -16,9 +16,9 @@ public class RedisListenerConfig { @Bean @Primary - public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) { + public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory factory) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); - container.setConnectionFactory(connectionFactory); + container.setConnectionFactory(factory); return container; } } diff --git a/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java index b4a49130..fd00a1ad 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java +++ b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java @@ -54,9 +54,10 @@ public void onMessage(Message message, byte[] pattern) { } String accessValue = expiredKey.substring(expiredKey.indexOf(":") + 1); // 分布式集群部署下防止一个过期被多个服务重复消费 - String qc = redisRepository.getAndSet("qc:" + accessValue, "1"); - if (StringUtils.isNotEmpty(qc) && "1".equals(qc)) { - log.debug("其他节点已经处理了该数据,次数跳过"); + String qc = "qc:" + accessValue; + String oldLock = redisRepository.getAndSet(qc, "1"); + if (StringUtils.isNotEmpty(oldLock) && "1".equals(oldLock)) { + log.debug("其他节点已经处理了该数据,跳过"); return; } byte[] accessBakKey = serializeKey(SecurityConstants.ACCESS_BAK + accessValue); @@ -77,7 +78,7 @@ public void onMessage(Message message, byte[] pattern) { } catch (Exception e) { log.error(e.getMessage()); } finally { - conn.del(); + conn.del(oldLock.getBytes()); conn.close(); } From c07527f7aab0aa9584f77c23b35a4034064b09cb Mon Sep 17 00:00:00 2001 From: lpphan Date: Sun, 20 Mar 2022 07:58:57 +0000 Subject: [PATCH 03/14] update zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java. --- .../com/central/oauth/listener/RedisKeyExpirationListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java index fd00a1ad..eb4e1db7 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java +++ b/zlt-uaa/src/main/java/com/central/oauth/listener/RedisKeyExpirationListener.java @@ -78,7 +78,7 @@ public void onMessage(Message message, byte[] pattern) { } catch (Exception e) { log.error(e.getMessage()); } finally { - conn.del(oldLock.getBytes()); + conn.del(serializeKey(qc)); conn.close(); } From e6fd65c271bc89b6b38635585429590c7ea959a1 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 10 Apr 2022 15:37:36 +0800 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4loadbalancer?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ConfigConstants.java | 10 ++ .../common/lb/chooser/IRuleChooser.java | 14 +++ .../common/lb/chooser/RandomRuleChooser.java | 27 ++++++ .../common/lb/chooser/RoundRuleChooser.java | 33 +++++++ .../lb/config/VerionAutoRegistryConfig.java | 18 ++++ .../lb/config/VersionLoadBalancerConfig.java | 70 ++++++++++++++ .../VersionRegisterBeanPostProcessor.java | 27 ++++++ .../common/lb/filter/LbIsolationFilter.java | 49 ++++++++++ .../lb/loadbalancer/VersionLoadBalancer.java | 95 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 +- .../src/main/resources/application.yml | 8 +- .../src/main/resources/application.yml | 7 +- 12 files changed, 358 insertions(+), 3 deletions(-) create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/IRuleChooser.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RandomRuleChooser.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RoundRuleChooser.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionRegisterBeanPostProcessor.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ConfigConstants.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ConfigConstants.java index cd8375cd..af2cadbd 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ConfigConstants.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/ConfigConstants.java @@ -11,4 +11,14 @@ public interface ConfigConstants { * 是否开启自定义隔离规则 */ String CONFIG_RIBBON_ISOLATION_ENABLED = "zlt.ribbon.isolation.enabled"; + + String CONFIG_LOADBALANCE_ISOLATION = "zlt.loadbalance.isolation"; + + String CONFIG_LOADBALANCE_ISOLATION_ENABLE = CONFIG_LOADBALANCE_ISOLATION + ".enabled"; + + String CONFIG_LOADBALANCE_ISOLATION_CHOOSER = CONFIG_LOADBALANCE_ISOLATION + ".chooser"; + + String CONFIG_LOADBALANCE_VERSION = "zlt.loadbalance.version"; + + } diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/IRuleChooser.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/IRuleChooser.java new file mode 100644 index 00000000..356d2c7d --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/IRuleChooser.java @@ -0,0 +1,14 @@ +package com.central.common.lb.chooser; + +import org.springframework.cloud.client.ServiceInstance; + +import java.util.List; + +/** + * service选择器类 + * + * @author jarvis create by 2022/3/13 + */ +public interface IRuleChooser { + ServiceInstance choose(List instances); +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RandomRuleChooser.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RandomRuleChooser.java new file mode 100644 index 00000000..aec82573 --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RandomRuleChooser.java @@ -0,0 +1,27 @@ +package com.central.common.lb.chooser; + +import com.alibaba.nacos.common.utils.CollectionUtils; +import lombok.extern.log4j.Log4j2; +import org.springframework.cloud.client.ServiceInstance; + +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +/** + * 随机的选择器 + * + * @author jarvis create by 2022/3/13 + */ +@Log4j2 +public class RandomRuleChooser implements IRuleChooser { + @Override + public ServiceInstance choose(List instances) { + if(CollectionUtils.isNotEmpty(instances)){ + int randomValue = ThreadLocalRandom.current().nextInt(instances.size()); + ServiceInstance serviceInstance = instances.get(randomValue); + log.info("选择了ip为{}, 端口为:{}的服务", serviceInstance.getHost(), serviceInstance.getPort()); + return serviceInstance; + } + return null; + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RoundRuleChooser.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RoundRuleChooser.java new file mode 100644 index 00000000..2817f0a9 --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/chooser/RoundRuleChooser.java @@ -0,0 +1,33 @@ +package com.central.common.lb.chooser; + +import com.alibaba.nacos.common.utils.CollectionUtils; +import lombok.extern.log4j.Log4j2; +import org.springframework.cloud.client.ServiceInstance; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * 轮询选择器 + * + * @author jarvis create by 2022/3/13 + */ +@Log4j2 +public class RoundRuleChooser implements IRuleChooser{ + + private AtomicInteger position; + + public RoundRuleChooser() { + this.position = new AtomicInteger(1000); + } + + @Override + public ServiceInstance choose(List instances) { + if(CollectionUtils.isNotEmpty(instances)){ + ServiceInstance serviceInstance = instances.get(Math.abs(position.incrementAndGet() % instances.size())); + log.info("选择了ip为{}, 端口为:{}的服务", serviceInstance.getHost(), serviceInstance.getPort()); + return serviceInstance; + } + return null; + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java new file mode 100644 index 00000000..6277726f --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java @@ -0,0 +1,18 @@ +package com.central.common.lb.config; + +import com.central.common.constant.ConfigConstants; +import com.central.common.lb.filter.LbIsolationFilter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients; +import org.springframework.context.annotation.Import; + +/** + * 示例 + * + * @author jarvis create by 2022/4/10 + */ +@LoadBalancerClients(defaultConfiguration = VersionLoadBalancerConfig.class) +@ConditionalOnProperty(prefix = ConfigConstants.CONFIG_LOADBALANCE_ISOLATION, name = "enabled", havingValue = "true", matchIfMissing = false) +@Import({VersionRegisterBeanPostProcessor.class, LbIsolationFilter.class}) +public class VerionAutoRegistryConfig { +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java new file mode 100644 index 00000000..b37b231f --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java @@ -0,0 +1,70 @@ +package com.central.common.lb.config; + +import com.central.common.constant.ConfigConstants; +import com.central.common.lb.chooser.IRuleChooser; +import com.central.common.lb.chooser.RoundRuleChooser; +import com.central.common.lb.loadbalancer.VersionLoadBalancer; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; +import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; +import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; +import org.springframework.util.ClassUtils; +import java.util.Objects; + + +/** + * 版本控制的路由选择类配置 + * + * @author jarvis create by 2022/3/9 + */ +@Log4j2 +public class VersionLoadBalancerConfig{ + + private IRuleChooser defaultRuleChooser = null; + + @Bean + @ConditionalOnMissingBean(IRuleChooser.class) + @ConditionalOnProperty(prefix = ConfigConstants.CONFIG_LOADBALANCE_ISOLATION, value = "chooser") + public IRuleChooser customRuleChooser(Environment environment, ApplicationContext context){ + + IRuleChooser chooser = new RoundRuleChooser(); + if (environment.containsProperty(ConfigConstants.CONFIG_LOADBALANCE_ISOLATION_CHOOSER)) { + String chooserRuleClassString = environment.getProperty(ConfigConstants.CONFIG_LOADBALANCE_ISOLATION_CHOOSER); + if(StringUtils.isNotBlank(chooserRuleClassString)){ + try { + Class ruleClass = ClassUtils.forName(chooserRuleClassString, context.getClassLoader()); + chooser = (IRuleChooser) ruleClass.newInstance(); + } catch (ClassNotFoundException e) { + log.error("没有找到定义的选择器,将使用内置的选择器", e); + } catch (InstantiationException e) { + log.error("没法创建定义的选择器,将使用内置的选择器", e); + } catch (IllegalAccessException e) { + log.error("没法创建定义的选择器,将使用内置的选择器", e); + } + } + } + return chooser; + } + + @Bean + @ConditionalOnMissingBean(value = IRuleChooser.class) + public IRuleChooser defaultRuleChooser(){ + return new RoundRuleChooser(); + } + + + @Bean + @ConditionalOnProperty(prefix = ConfigConstants.CONFIG_LOADBALANCE_ISOLATION, name = "enabled", havingValue = "true", matchIfMissing = false) + public ReactorServiceInstanceLoadBalancer versionServiceLoadBalancer(Environment environment + , LoadBalancerClientFactory loadBalancerClientFactory, IRuleChooser ruleChooser){ + String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME); + return new VersionLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class) + , name, ruleChooser); + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionRegisterBeanPostProcessor.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionRegisterBeanPostProcessor.java new file mode 100644 index 00000000..7f5a3d1f --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionRegisterBeanPostProcessor.java @@ -0,0 +1,27 @@ +package com.central.common.lb.config; + +import com.alibaba.cloud.nacos.NacosDiscoveryProperties; +import com.alibaba.nacos.common.utils.StringUtils; +import com.central.common.constant.CommonConstant; +import com.central.common.constant.ConfigConstants; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.BeanPostProcessor; + +/** + * 将版本注册到注册中心的组件 + * + * @author jarvis create by 2022/3/20 + */ +public class VersionRegisterBeanPostProcessor implements BeanPostProcessor { + @Value("${"+ ConfigConstants.CONFIG_LOADBALANCE_VERSION+":}") + private String version; + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if(bean instanceof NacosDiscoveryProperties && StringUtils.isNotBlank(version)){ + NacosDiscoveryProperties nacosDiscoveryProperties = (NacosDiscoveryProperties) bean; + nacosDiscoveryProperties.getMetadata().putIfAbsent(CommonConstant.METADATA_VERSION, version); + } + return bean; + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java new file mode 100644 index 00000000..e18e7c00 --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java @@ -0,0 +1,49 @@ +package com.central.common.lb.filter; + +import cn.hutool.core.util.StrUtil; +import com.central.common.constant.CommonConstant; +import com.central.common.constant.ConfigConstants; +import com.central.common.context.LbIsolationContextHolder; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * web过滤器 + * 作用:将请求中的存放在参数和header的版本号获取出来并存入TreadLocal中 + * + * @author jarvis create by 2022/3/9 + */ +@ConditionalOnClass(Filter.class) +public class LbIsolationFilter extends OncePerRequestFilter { + @Value("${" + ConfigConstants.CONFIG_LOADBALANCE_ISOLATION_ENABLE + ":false}") + private boolean enableIsolation; + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) { + return !enableIsolation; + } + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + try { + String version = StringUtils.isNotBlank(request.getParameter(CommonConstant.Z_L_T_VERSION))? + request.getParameter(CommonConstant.Z_L_T_VERSION): + request.getHeader(CommonConstant.Z_L_T_VERSION); + if(StrUtil.isNotEmpty(version)){ + LbIsolationContextHolder.setVersion(version); + } + + filterChain.doFilter(request, response); + } finally { + LbIsolationContextHolder.clear(); + } + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java new file mode 100644 index 00000000..286b84f3 --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java @@ -0,0 +1,95 @@ +package com.central.common.lb.loadbalancer; + +import com.central.common.constant.CommonConstant; +import com.central.common.context.LbIsolationContextHolder; +import com.central.common.lb.chooser.IRuleChooser; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.loadbalancer.DefaultResponse; +import org.springframework.cloud.client.loadbalancer.EmptyResponse; +import org.springframework.cloud.client.loadbalancer.Request; +import org.springframework.cloud.client.loadbalancer.Response; +import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; +import org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancer; +import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; +import org.springframework.cloud.loadbalancer.support.SimpleObjectProvider; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; + +/** + * 自定义版本路由选择 + * + * @author jarvis create by 2022/3/9 + */ +@Log4j2 +public class VersionLoadBalancer implements ReactorServiceInstanceLoadBalancer { + + private final static String KEY_DEFAULT = "default"; + + private ObjectProvider serviceInstanceListSuppliers; + + private String serviceId; + + private IRuleChooser ruleChooser; + + public VersionLoadBalancer(ObjectProvider serviceInstanceListSuppliers, String serviceId, IRuleChooser ruleChooser) { + this.serviceInstanceListSuppliers = serviceInstanceListSuppliers; + this.serviceId = serviceId; + this.ruleChooser = ruleChooser; + } + + @Override + public Mono> choose(Request request) { + return serviceInstanceListSuppliers.getIfAvailable().get(request).next().map(this::getInstanceResponse); + } + + /** + * 1. 先获取到拦截的版本,如果不为空的话就将service列表过滤,寻找metadata中哪个服务是配置的版本, + * 如果版本为空则不需要进行过滤直接提交给service选择器进行选择 + * 2. 如果没有找到版本对应的实例,则找所有版本为空或者版本号为default的实例 + * 3.将instance列表提交到选择器根据对应的策略返回一个instance + * @param instances + * @return + */ + private Response getInstanceResponse(Listinstances){ + String version = LbIsolationContextHolder.getVersion(); + log.debug("选择的版本号为:{}", version); + List filteredServiceIstanceList = instances; + if(StringUtils.isNotBlank(version)){ + if(CollectionUtils.isNotEmpty(instances)){ + filteredServiceIstanceList = instances.stream() + .filter(item->item.getMetadata().containsKey(CommonConstant.METADATA_VERSION)&& + version.equals(item.getMetadata().get(CommonConstant.METADATA_VERSION))) + .collect(Collectors.toList()); + } + } + // 如果没有找到对应的版本实例时,选择版本号为空的或这版本为default的实例 + if(CollectionUtils.isEmpty(filteredServiceIstanceList)){ + filteredServiceIstanceList = instances.stream() + .filter(item->!item.getMetadata().containsKey(CommonConstant.METADATA_VERSION) + || "default".equals(item.getMetadata().get(CommonConstant.METADATA_VERSION))) + .collect(Collectors.toList()); + } + // 经过两轮过滤后如果能找到的话就选择,不然返回空 + if(CollectionUtils.isNotEmpty(filteredServiceIstanceList)){ + ServiceInstance serviceInstance = this.ruleChooser.choose(filteredServiceIstanceList); + if(!Objects.isNull(serviceInstance)){ + log.debug("使用serviceId为:{}服务, 选择version为:{}, 地址:{}:{},", serviceId, version + , serviceInstance.getHost(), serviceInstance.getPort()); + return new DefaultResponse(serviceInstance); + } + } + // 返回空的返回体 + return new EmptyResponse(); + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories index bd79ca62..06406df3 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,2 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.central.common.lb.RestTemplateAutoConfigure \ No newline at end of file +com.central.common.lb.RestTemplateAutoConfigure,\ +com.central.common.lb.config.VerionAutoRegistryConfig \ No newline at end of file diff --git a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/src/main/resources/application.yml b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/src/main/resources/application.yml index cd402049..7133edbd 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/src/main/resources/application.yml +++ b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/src/main/resources/application.yml @@ -16,4 +16,10 @@ tx-lcn: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull username: ${zlt.datasource.username} - password: ${zlt.datasource.password} \ No newline at end of file + password: ${zlt.datasource.password} +zlt: + loadbalance: + version: test + isolation: + enabled: true + chooser: com.central.common.lb.chooser.RandomRuleChooser diff --git a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/src/main/resources/application.yml b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/src/main/resources/application.yml index cd402049..68d7e81d 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/src/main/resources/application.yml +++ b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/src/main/resources/application.yml @@ -16,4 +16,9 @@ tx-lcn: driver-class-name: com.mysql.cj.jdbc.Driver jdbc-url: jdbc:mysql://${zlt.datasource.ip}:3306/tx_logger?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull username: ${zlt.datasource.username} - password: ${zlt.datasource.password} \ No newline at end of file + password: ${zlt.datasource.password} +zlt: + loadbalance: + version: test + isolation: + enabled: true \ No newline at end of file From 4d0178611f42c49f9d7059630a1a10a34afc7d00 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 10 Apr 2022 15:42:06 +0800 Subject: [PATCH 05/14] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B3=A8=E5=86=8C=E7=89=88=E6=9C=AC=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E7=9A=84=E6=8E=A7=E5=88=B6=E5=99=A8=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...AutoRegistryConfig.java => VerionIsolationAutoConfig.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/{VerionAutoRegistryConfig.java => VerionIsolationAutoConfig.java} (93%) diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java similarity index 93% rename from zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java rename to zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java index 6277726f..d8375743 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionAutoRegistryConfig.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java @@ -7,12 +7,12 @@ import org.springframework.context.annotation.Import; /** - * 示例 + * * * @author jarvis create by 2022/4/10 */ @LoadBalancerClients(defaultConfiguration = VersionLoadBalancerConfig.class) @ConditionalOnProperty(prefix = ConfigConstants.CONFIG_LOADBALANCE_ISOLATION, name = "enabled", havingValue = "true", matchIfMissing = false) @Import({VersionRegisterBeanPostProcessor.class, LbIsolationFilter.class}) -public class VerionAutoRegistryConfig { +public class VerionIsolationAutoConfig { } From b7aa931fb22b29ffc7a94b453ddc725ecd3281d1 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Tue, 19 Apr 2022 22:33:04 +0800 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20=E6=8F=90=E4=BA=A4=E7=94=B1?= =?UTF-8?q?=E4=BA=8E=E6=94=B9=E5=90=8D=E5=90=8E=E6=B2=A1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?spring.factories=E7=9A=84=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=B1=BB=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/META-INF/spring.factories | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories index 06406df3..6154b24d 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.central.common.lb.RestTemplateAutoConfigure,\ -com.central.common.lb.config.VerionAutoRegistryConfig \ No newline at end of file +com.central.common.lb.config.VerionIsolationAutoConfig \ No newline at end of file From 7526f18d4a10a41a17a7a8cd6f5f9633c5c07ccb Mon Sep 17 00:00:00 2001 From: zhult13 Date: Fri, 6 May 2022 23:22:55 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E9=80=82=E9=85=8D=20mybatis-plus=20?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E6=96=B0=E9=85=8D=E7=BD=AE=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/config/MybatisPlusAutoConfigure.java | 29 ++++++------ .../db/config/TenantAutoConfigure.java | 34 +++----------- .../interceptor/CustomTenantInterceptor.java | 44 +++++++++++++++++++ 3 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java diff --git a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java index 80132289..2b1e855e 100644 --- a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java +++ b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/MybatisPlusAutoConfigure.java @@ -1,12 +1,12 @@ package com.central.db.config; -import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import com.baomidou.mybatisplus.core.parser.ISqlParserFilter; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; -import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler; -import com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.central.common.properties.TenantProperties; +import com.central.db.interceptor.CustomTenantInterceptor; import com.central.db.properties.MybatisPlusAutoFillProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -26,10 +26,7 @@ @EnableConfigurationProperties(MybatisPlusAutoFillProperties.class) public class MybatisPlusAutoConfigure { @Autowired - private TenantHandler tenantHandler; - - @Autowired - private ISqlParserFilter sqlParserFilter; + private TenantLineHandler tenantLineHandler; @Autowired private TenantProperties tenantProperties; @@ -41,17 +38,17 @@ public class MybatisPlusAutoConfigure { * 分页插件,自动识别数据库类型 */ @Bean - public PaginationInterceptor paginationInterceptor() { - PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor(); + mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); boolean enableTenant = tenantProperties.getEnable(); //是否开启多租户隔离 if (enableTenant) { - TenantSqlParser tenantSqlParser = new TenantSqlParser() - .setTenantHandler(tenantHandler); - paginationInterceptor.setSqlParserList(CollUtil.toList(tenantSqlParser)); - paginationInterceptor.setSqlParserFilter(sqlParserFilter); + CustomTenantInterceptor tenantInterceptor = new CustomTenantInterceptor( + tenantLineHandler, tenantProperties.getIgnoreSqls()); + mpInterceptor.addInnerInterceptor(tenantInterceptor); } - return paginationInterceptor; + return mpInterceptor; } @Bean diff --git a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java index 40f38d6e..8778dd6d 100644 --- a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java +++ b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/config/TenantAutoConfigure.java @@ -1,14 +1,11 @@ package com.central.db.config; -import com.baomidou.mybatisplus.core.parser.ISqlParserFilter; -import com.baomidou.mybatisplus.core.parser.SqlParserHelper; -import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler; +import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; import com.central.common.context.TenantContextHolder; import com.central.common.properties.TenantProperties; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.NullValue; import net.sf.jsqlparser.expression.StringValue; -import org.apache.ibatis.mapping.MappedStatement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -25,13 +22,13 @@ public class TenantAutoConfigure { private TenantProperties tenantProperties; @Bean - public TenantHandler tenantHandler() { - return new TenantHandler() { + public TenantLineHandler tenantLineHandler() { + return new TenantLineHandler() { /** * 获取租户id */ @Override - public Expression getTenantId(boolean where) { + public Expression getTenantId() { String tenant = TenantContextHolder.getTenant(); if (tenant != null) { return new StringValue(TenantContextHolder.getTenant()); @@ -39,37 +36,16 @@ public Expression getTenantId(boolean where) { return new NullValue(); } - /** - * 获取租户列名 - */ - @Override - public String getTenantIdColumn() { - return "tenant_id"; - } - /** * 过滤不需要根据租户隔离的表 * @param tableName 表名 */ @Override - public boolean doTableFilter(String tableName) { + public boolean ignoreTable(String tableName) { return tenantProperties.getIgnoreTables().stream().anyMatch( (e) -> e.equalsIgnoreCase(tableName) ); } }; } - - /** - * 过滤不需要根据租户隔离的MappedStatement - */ - @Bean - public ISqlParserFilter sqlParserFilter() { - return metaObject -> { - MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject); - return tenantProperties.getIgnoreSqls().stream().anyMatch( - (e) -> e.equalsIgnoreCase(ms.getId()) - ); - }; - } } diff --git a/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java new file mode 100644 index 00000000..f2083e7f --- /dev/null +++ b/zlt-commons/zlt-db-spring-boot-starter/src/main/java/com/central/db/interceptor/CustomTenantInterceptor.java @@ -0,0 +1,44 @@ +package com.central.db.interceptor; + +import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; +import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; +import org.apache.ibatis.executor.Executor; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.MappedStatement; +import org.apache.ibatis.session.ResultHandler; +import org.apache.ibatis.session.RowBounds; + +import java.sql.SQLException; +import java.util.List; + +/** + * MyBatis-plus租户拦截器 + * + * @author zlt + * @version 1.0 + * @date 2022/5/6 + *

+ * Blog: https://zlt2000.gitee.io + * Github: https://github.com/zlt2000 + */ +public class CustomTenantInterceptor extends TenantLineInnerInterceptor { + private List ignoreSqls; + + public CustomTenantInterceptor(TenantLineHandler tenantLineHandler, List ignoreSqls) { + super(tenantLineHandler); + this.ignoreSqls = ignoreSqls; + } + + @Override + public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds + , ResultHandler resultHandler, BoundSql boundSql) throws SQLException { + if (isIgnoreMappedStatement(ms.getId())) { + return; + } + super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql); + } + + private boolean isIgnoreMappedStatement(String msId) { + return ignoreSqls.stream().anyMatch((e) -> e.equalsIgnoreCase(msId)); + } +} From f206ae93e1e695347c1f1fb99f6fd63a7f42809d Mon Sep 17 00:00:00 2001 From: zhult13 Date: Fri, 6 May 2022 23:28:43 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E5=8D=87=E7=BA=A7mybatis-plus=E5=88=B03.?= =?UTF-8?q?5.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../src/main/java/com/central/file/model/FileInfo.java | 5 ----- .../src/main/java/com/central/common/model/SuperEntity.java | 5 ----- .../com/central/common/service/impl/SuperServiceImpl.java | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 6d37a32a..9749377b 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 3.16.1 1.6.2 5.7.20 - 3.4.0 + 3.5.1 3.8.1 7.2.28 4.1.3 diff --git a/zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java b/zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java index a6622a7b..2e7e300b 100644 --- a/zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java +++ b/zlt-business/file-center/src/main/java/com/central/file/model/FileInfo.java @@ -56,9 +56,4 @@ public class FileInfo extends Model { private Date createTime; @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; - - @Override - protected Serializable pkVal() { - return this.id; - } } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java index f7778346..30894a40 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/model/SuperEntity.java @@ -27,9 +27,4 @@ public class SuperEntity> extends Model { private Date createTime; @TableField(fill = FieldFill.INSERT_UPDATE) private Date updateTime; - - @Override - protected Serializable pkVal() { - return this.id; - } } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java index 27df85fe..8c678084 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/service/impl/SuperServiceImpl.java @@ -42,7 +42,7 @@ public boolean saveIdempotency(T entity, DistributedLock locker, String lockKey, ) { if (lock != null) { //判断记录是否已存在 - int count = super.count(countWrapper); + long count = super.count(countWrapper); if (count == 0) { return super.save(entity); } else { From b0b91ef0b7b84fc6de60f7c3ee9358d957787dec Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 8 May 2022 16:22:47 +0800 Subject: [PATCH 09/14] =?UTF-8?q?feat:=20loadBalancer=E5=85=BC=E5=AE=B9gat?= =?UTF-8?q?eway=E5=92=8C=E6=99=AE=E9=80=9Ahttp=E8=AF=B7=E6=B1=82=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=A2=9E=E5=8A=A0webflux=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lb/annotation/EnableFeignInterceptor.java | 4 +- ...eignHttpImportBeanDefinitionRegistrar.java | 33 +++++++++++++++ .../lb/config/FeignHttpInterceptorConfig.java | 15 +++++++ .../lb/config/VerionIsolationAutoConfig.java | 3 +- .../lb/loadbalancer/VersionLoadBalancer.java | 35 ++++++++++------ .../central/common/lb/utils/QueryUtils.java | 42 +++++++++++++++++++ 6 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java create mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/utils/QueryUtils.java diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java index 9bd4c02e..2346de47 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java @@ -1,5 +1,6 @@ package com.central.common.lb.annotation; +import com.central.common.lb.config.FeignHttpImportBeanDefinitionRegistrar; import com.central.common.lb.config.FeignHttpInterceptorConfig; import com.central.common.lb.config.FeignInterceptorConfig; import org.springframework.context.annotation.Import; @@ -17,7 +18,8 @@ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@Import({FeignInterceptorConfig.class, FeignHttpInterceptorConfig.class}) +@Import(FeignHttpImportBeanDefinitionRegistrar.class) +//@Import({FeignInterceptorConfig.class, FeignHttpInterceptorConfig.class}) public @interface EnableFeignInterceptor { } diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java new file mode 100644 index 00000000..ee5eb33f --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java @@ -0,0 +1,33 @@ +package com.central.common.lb.config; + +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.BeanNameGenerator; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.util.ClassUtils; + +import javax.servlet.Filter; + +/** + * 示例 + * + * @author jarvis create by 2022/5/8 + */ +public class FeignHttpImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar { + @Override + public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) { + try { + Class.forName("javax.servlet.Filter", false, registry.getClass().getClassLoader()); + AbstractBeanDefinition feignHttpInterceptorConfig = BeanDefinitionBuilder.genericBeanDefinition(FeignHttpInterceptorConfig.class).getBeanDefinition(); + registry.registerBeanDefinition(importBeanNameGenerator.generateBeanName(feignHttpInterceptorConfig, registry), feignHttpInterceptorConfig); + + + AbstractBeanDefinition feignInterceptorConfig = BeanDefinitionBuilder.genericBeanDefinition(FeignInterceptorConfig.class).getBeanDefinition(); + registry.registerBeanDefinition(importBeanNameGenerator.generateBeanName(feignInterceptorConfig, registry), feignInterceptorConfig); + } catch (ClassNotFoundException e) { + } + } +} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java index 7140c7ba..afdda4c1 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java @@ -2,7 +2,10 @@ import com.central.common.constant.CommonConstant; import com.central.common.constant.SecurityConstants; +import com.central.common.lb.utils.QueryUtils; import feign.RequestInterceptor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.context.annotation.Bean; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -12,6 +15,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; +import java.util.Map; /** * feign拦截器,只包含http相关数据 @@ -37,6 +41,7 @@ public void initialize() { * 使用feign client访问别的微服务时,将上游传过来的access_token、username、roles等信息放入header传递给下一个服务 */ @Bean + @ConditionalOnClass(HttpServletRequest.class) public RequestInterceptor httpFeignInterceptor() { return template -> { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder @@ -55,6 +60,16 @@ public RequestInterceptor httpFeignInterceptor() { } } } + // 增加从query上获取版本 + String queryString = request.getQueryString(); + if(StringUtils.isNotBlank(queryString)){ + Map map = QueryUtils.getQueryMap(queryString); + for (String requestHeader : requestHeaders) { + if(map.containsKey(requestHeader)){ + template.header(requestHeader, map.get(requestHeader)); + } + } + } //传递access_token,无网络隔离时需要传递 /* String token = extractHeaderToken(request); diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java index d8375743..2ecd5166 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VerionIsolationAutoConfig.java @@ -1,7 +1,6 @@ package com.central.common.lb.config; import com.central.common.constant.ConfigConstants; -import com.central.common.lb.filter.LbIsolationFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients; import org.springframework.context.annotation.Import; @@ -13,6 +12,6 @@ */ @LoadBalancerClients(defaultConfiguration = VersionLoadBalancerConfig.class) @ConditionalOnProperty(prefix = ConfigConstants.CONFIG_LOADBALANCE_ISOLATION, name = "enabled", havingValue = "true", matchIfMissing = false) -@Import({VersionRegisterBeanPostProcessor.class, LbIsolationFilter.class}) +@Import({VersionRegisterBeanPostProcessor.class}) public class VerionIsolationAutoConfig { } diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java index 286b84f3..cfde5ff0 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java @@ -3,15 +3,15 @@ import com.central.common.constant.CommonConstant; import com.central.common.context.LbIsolationContextHolder; import com.central.common.lb.chooser.IRuleChooser; +import com.central.common.lb.utils.QueryUtils; +import com.google.common.collect.Maps; import lombok.extern.log4j.Log4j2; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.ObjectProvider; import org.springframework.cloud.client.ServiceInstance; -import org.springframework.cloud.client.loadbalancer.DefaultResponse; -import org.springframework.cloud.client.loadbalancer.EmptyResponse; -import org.springframework.cloud.client.loadbalancer.Request; -import org.springframework.cloud.client.loadbalancer.Response; +import org.springframework.cloud.client.loadbalancer.*; import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; import org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancer; import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; @@ -19,10 +19,8 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.net.URI; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; @@ -50,9 +48,24 @@ public VersionLoadBalancer(ObjectProvider serviceIn @Override public Mono> choose(Request request) { - return serviceInstanceListSuppliers.getIfAvailable().get(request).next().map(this::getInstanceResponse); + // 从request中获取版本,兼容webflux方式 + RequestData requestData = ((RequestDataContext) (request.getContext())).getClientRequest(); + String version = getVersionFromRequestData(requestData); + log.debug("选择的版本号为:{}", version); + return serviceInstanceListSuppliers.getIfAvailable().get(request).next().map(instanceList->{ + return getInstanceResponse(instanceList, version); + }); } + private String getVersionFromRequestData(RequestData requestData){ + Map queryMap = QueryUtils.getQueryMap(requestData.getUrl()); + if(MapUtils.isNotEmpty(queryMap)&& queryMap.containsKey(CommonConstant.Z_L_T_VERSION)&& StringUtils.isNotBlank(queryMap.get(CommonConstant.Z_L_T_VERSION))){ + return queryMap.get(CommonConstant.Z_L_T_VERSION); + }else if(requestData.getHeaders().containsKey(CommonConstant.Z_L_T_VERSION)){ + return requestData.getHeaders().get(CommonConstant.Z_L_T_VERSION).get(0); + } + return null; + } /** * 1. 先获取到拦截的版本,如果不为空的话就将service列表过滤,寻找metadata中哪个服务是配置的版本, * 如果版本为空则不需要进行过滤直接提交给service选择器进行选择 @@ -61,9 +74,7 @@ public Mono> choose(Request request) { * @param instances * @return */ - private Response getInstanceResponse(Listinstances){ - String version = LbIsolationContextHolder.getVersion(); - log.debug("选择的版本号为:{}", version); + private Response getInstanceResponse(Listinstances, String version){ List filteredServiceIstanceList = instances; if(StringUtils.isNotBlank(version)){ if(CollectionUtils.isNotEmpty(instances)){ diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/utils/QueryUtils.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/utils/QueryUtils.java new file mode 100644 index 00000000..2321d5bf --- /dev/null +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/utils/QueryUtils.java @@ -0,0 +1,42 @@ +package com.central.common.lb.utils; + +import org.apache.commons.lang3.StringUtils; + +import java.net.URI; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * 解析request的query参数工具 + * + * @author jarvis create by 2022/5/8 + */ +public class QueryUtils { + /** + * 通过query字符串得到参数的map + * @param queryString ?后的字符 + * @return + */ + public static Map getQueryMap(String queryString){ + if(StringUtils.isNotBlank(queryString)){ + return Arrays.stream(queryString.split("&")).map(item -> item.split("=")) + .collect(Collectors.toMap(key -> key[0], value -> value.length > 1 && StringUtils.isNotBlank(value[1]) ? value[1] : "")); + } + return Collections.emptyMap(); + } + + /** + * 通过url获取参数map + * @param uri + * @return + */ + public static Map getQueryMap(URI uri){ + if(Objects.nonNull(uri)){ + return getQueryMap(uri.getQuery()); + } + return Collections.emptyMap(); + } +} From c80cb0bdd3b658731c3356d94933ff47a421c465 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 8 May 2022 16:25:27 +0800 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20loadBalancer=E5=85=BC=E5=AE=B9gat?= =?UTF-8?q?eway=E5=92=8C=E6=99=AE=E9=80=9Ahttp=E8=AF=B7=E6=B1=82=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=A2=9E=E5=8A=A0webflux=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/lb/filter/LbIsolationFilter.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java deleted file mode 100644 index e18e7c00..00000000 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/filter/LbIsolationFilter.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.central.common.lb.filter; - -import cn.hutool.core.util.StrUtil; -import com.central.common.constant.CommonConstant; -import com.central.common.constant.ConfigConstants; -import com.central.common.context.LbIsolationContextHolder; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.web.filter.OncePerRequestFilter; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * web过滤器 - * 作用:将请求中的存放在参数和header的版本号获取出来并存入TreadLocal中 - * - * @author jarvis create by 2022/3/9 - */ -@ConditionalOnClass(Filter.class) -public class LbIsolationFilter extends OncePerRequestFilter { - @Value("${" + ConfigConstants.CONFIG_LOADBALANCE_ISOLATION_ENABLE + ":false}") - private boolean enableIsolation; - - @Override - protected boolean shouldNotFilter(HttpServletRequest request) { - return !enableIsolation; - } - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - try { - String version = StringUtils.isNotBlank(request.getParameter(CommonConstant.Z_L_T_VERSION))? - request.getParameter(CommonConstant.Z_L_T_VERSION): - request.getHeader(CommonConstant.Z_L_T_VERSION); - if(StrUtil.isNotEmpty(version)){ - LbIsolationContextHolder.setVersion(version); - } - - filterChain.doFilter(request, response); - } finally { - LbIsolationContextHolder.clear(); - } - } -} From 1e9f3558ee682bc09b3fbf43920c2c77c2bf47b4 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 8 May 2022 17:30:15 +0800 Subject: [PATCH 11/14] =?UTF-8?q?feat:=201.=20=E4=BF=AE=E6=94=B9feign?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=EF=BC=8C=E7=89=88=E6=9C=AC=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E5=8F=AA=E4=BB=8Eheader=E4=B8=AD=E8=8E=B7=E5=8F=962.?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC=E9=80=89=E6=8B=A9?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=80=89=E6=8B=A9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=B8=BA=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC3.=20=E8=BF=98=E5=8E=9FFeignIntercptor?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lb/annotation/EnableFeignInterceptor.java | 4 +-- ...eignHttpImportBeanDefinitionRegistrar.java | 33 ------------------- .../lb/config/FeignHttpInterceptorConfig.java | 10 ------ .../lb/loadbalancer/VersionLoadBalancer.java | 3 +- 4 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java index 2346de47..9bd4c02e 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/annotation/EnableFeignInterceptor.java @@ -1,6 +1,5 @@ package com.central.common.lb.annotation; -import com.central.common.lb.config.FeignHttpImportBeanDefinitionRegistrar; import com.central.common.lb.config.FeignHttpInterceptorConfig; import com.central.common.lb.config.FeignInterceptorConfig; import org.springframework.context.annotation.Import; @@ -18,8 +17,7 @@ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@Import(FeignHttpImportBeanDefinitionRegistrar.class) -//@Import({FeignInterceptorConfig.class, FeignHttpInterceptorConfig.class}) +@Import({FeignInterceptorConfig.class, FeignHttpInterceptorConfig.class}) public @interface EnableFeignInterceptor { } diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java deleted file mode 100644 index ee5eb33f..00000000 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpImportBeanDefinitionRegistrar.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.central.common.lb.config; - -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanNameGenerator; -import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.util.ClassUtils; - -import javax.servlet.Filter; - -/** - * 示例 - * - * @author jarvis create by 2022/5/8 - */ -public class FeignHttpImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar { - @Override - public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) { - try { - Class.forName("javax.servlet.Filter", false, registry.getClass().getClassLoader()); - AbstractBeanDefinition feignHttpInterceptorConfig = BeanDefinitionBuilder.genericBeanDefinition(FeignHttpInterceptorConfig.class).getBeanDefinition(); - registry.registerBeanDefinition(importBeanNameGenerator.generateBeanName(feignHttpInterceptorConfig, registry), feignHttpInterceptorConfig); - - - AbstractBeanDefinition feignInterceptorConfig = BeanDefinitionBuilder.genericBeanDefinition(FeignInterceptorConfig.class).getBeanDefinition(); - registry.registerBeanDefinition(importBeanNameGenerator.generateBeanName(feignInterceptorConfig, registry), feignInterceptorConfig); - } catch (ClassNotFoundException e) { - } - } -} diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java index afdda4c1..4e0e006a 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/FeignHttpInterceptorConfig.java @@ -60,16 +60,6 @@ public RequestInterceptor httpFeignInterceptor() { } } } - // 增加从query上获取版本 - String queryString = request.getQueryString(); - if(StringUtils.isNotBlank(queryString)){ - Map map = QueryUtils.getQueryMap(queryString); - for (String requestHeader : requestHeaders) { - if(map.containsKey(requestHeader)){ - template.header(requestHeader, map.get(requestHeader)); - } - } - } //传递access_token,无网络隔离时需要传递 /* String token = extractHeaderToken(request); diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java index cfde5ff0..5c01e63c 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java @@ -87,7 +87,8 @@ private Response getInstanceResponse(Listinsta // 如果没有找到对应的版本实例时,选择版本号为空的或这版本为default的实例 if(CollectionUtils.isEmpty(filteredServiceIstanceList)){ filteredServiceIstanceList = instances.stream() - .filter(item->!item.getMetadata().containsKey(CommonConstant.METADATA_VERSION) + .filter(item->!item.getMetadata().containsKey(CommonConstant.METADATA_VERSION)|| + StringUtils.isBlank(item.getMetadata().get(CommonConstant.METADATA_VERSION)) || "default".equals(item.getMetadata().get(CommonConstant.METADATA_VERSION))) .collect(Collectors.toList()); } From e0f941cf5c9b365ddb65187ea630ede540b763e1 Mon Sep 17 00:00:00 2001 From: jarvis <649219050@qq.com> Date: Sun, 8 May 2022 17:31:01 +0800 Subject: [PATCH 12/14] =?UTF-8?q?feat:=20gateway=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=B0=86query=E5=8F=82=E6=95=B0=E4=B8=AD=E5=B8=A6=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E7=9A=84=E5=8F=82=E6=95=B0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=88=B0header=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/VersionLbIsolationFilter.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 zlt-gateway/sc-gateway/src/main/java/com/central/gateway/filter/VersionLbIsolationFilter.java diff --git a/zlt-gateway/sc-gateway/src/main/java/com/central/gateway/filter/VersionLbIsolationFilter.java b/zlt-gateway/sc-gateway/src/main/java/com/central/gateway/filter/VersionLbIsolationFilter.java new file mode 100644 index 00000000..fab1c00a --- /dev/null +++ b/zlt-gateway/sc-gateway/src/main/java/com/central/gateway/filter/VersionLbIsolationFilter.java @@ -0,0 +1,45 @@ +package com.central.gateway.filter; + +import com.central.common.constant.CommonConstant; +import com.central.common.constant.ConfigConstants; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.List; + +/** + * 示例 + * + * @author jarvis create by 2022/5/8 + */ +@Component +public class VersionLbIsolationFilter implements GlobalFilter, Ordered { + + @Value("${"+ ConfigConstants.CONFIG_LOADBALANCE_ISOLATION_ENABLE+":}") + private Boolean enableVersionControl; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + if(Boolean.TRUE.equals(enableVersionControl) + && exchange.getRequest().getQueryParams().containsKey(CommonConstant.Z_L_T_VERSION)){ + String version = exchange.getRequest().getQueryParams().get(CommonConstant.Z_L_T_VERSION).get(0); + ServerHttpRequest rebuildRequest = exchange.getRequest().mutate().headers(header -> { + header.add(CommonConstant.Z_L_T_VERSION, version); + }).build(); + ServerWebExchange rebuildServerWebExchange = exchange.mutate().request(rebuildRequest).build(); + return chain.filter(rebuildServerWebExchange); + } + return chain.filter(exchange); + } + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE; + } +} From 1e61901cb6220dcc4a6b11b84ecf00d62faa89f9 Mon Sep 17 00:00:00 2001 From: zhult13 Date: Sun, 8 May 2022 20:22:32 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E5=8D=87=E7=BA=A7springboot=E4=B8=8Espri?= =?UTF-8?q?ngcloud=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++--- .../common/lb/config/VersionLoadBalancerConfig.java | 2 -- .../common/lb/loadbalancer/VersionLoadBalancer.java | 7 ------- zlt-config/src/main/resources/application-dev.properties | 5 ++++- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 9749377b..810a253a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ UTF-8 8 2021.1 - 2.5.9 - 2020.0.4 + 2.5.13 + 2020.0.5 4.4 2.0.1 0.9.1 @@ -32,7 +32,7 @@ 7.2.28 4.1.3 4.1.1 - 2.5.5 + 2.5.6 1.7 2.7 5.0.2.RELEASE diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java index b37b231f..e34964e7 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/config/VersionLoadBalancerConfig.java @@ -15,8 +15,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; import org.springframework.util.ClassUtils; -import java.util.Objects; - /** * 版本控制的路由选择类配置 diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java index 5c01e63c..6b8c4acd 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/src/main/java/com/central/common/lb/loadbalancer/VersionLoadBalancer.java @@ -1,10 +1,8 @@ package com.central.common.lb.loadbalancer; import com.central.common.constant.CommonConstant; -import com.central.common.context.LbIsolationContextHolder; import com.central.common.lb.chooser.IRuleChooser; import com.central.common.lb.utils.QueryUtils; -import com.google.common.collect.Maps; import lombok.extern.log4j.Log4j2; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -13,15 +11,10 @@ import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.loadbalancer.*; import org.springframework.cloud.loadbalancer.core.ReactorServiceInstanceLoadBalancer; -import org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancer; import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; -import org.springframework.cloud.loadbalancer.support.SimpleObjectProvider; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.net.URI; import java.util.*; -import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; /** diff --git a/zlt-config/src/main/resources/application-dev.properties b/zlt-config/src/main/resources/application-dev.properties index 091ab6e3..43d5ef6f 100644 --- a/zlt-config/src/main/resources/application-dev.properties +++ b/zlt-config/src/main/resources/application-dev.properties @@ -34,4 +34,7 @@ zlt.trace.enable=true zlt.ribbon.isolation.enabled=false ##### mybatis-plus打印完整sql(只适用于开发环境) -mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file +mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl + +# 开启版本路由 +#zlt.loadbalance.isolation.enabled=true \ No newline at end of file From d907c13fbc7c152a38593864bffe075e178a3936 Mon Sep 17 00:00:00 2001 From: zhult13 Date: Sun, 8 May 2022 20:27:37 +0800 Subject: [PATCH 14/14] update to v5.3.0 --- README.md | 6 +++--- pom.xml | 2 +- zlt-business/code-generator/pom.xml | 2 +- zlt-business/file-center/pom.xml | 2 +- zlt-business/pom.xml | 2 +- zlt-business/search-center/pom.xml | 2 +- zlt-business/search-center/search-client/pom.xml | 2 +- zlt-business/search-center/search-server/pom.xml | 2 +- zlt-business/user-center/pom.xml | 2 +- zlt-commons/pom.xml | 2 +- zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-common-core/pom.xml | 2 +- .../java/com/central/common/constant/CommonConstant.java | 2 +- zlt-commons/zlt-common-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-db-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-log-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-oss-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-redis-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml | 2 +- zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml | 2 +- zlt-config/pom.xml | 2 +- zlt-demo/dubbo-demo/pom.xml | 2 +- zlt-demo/pom.xml | 2 +- zlt-demo/rocketmq-demo/pom.xml | 2 +- zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml | 2 +- zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml | 2 +- zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml | 2 +- zlt-demo/seata-demo/account-service/pom.xml | 2 +- zlt-demo/seata-demo/business-service/pom.xml | 2 +- zlt-demo/seata-demo/order-service/pom.xml | 2 +- zlt-demo/seata-demo/pom.xml | 2 +- zlt-demo/seata-demo/seata-common-starter/pom.xml | 2 +- zlt-demo/seata-demo/storage-service/pom.xml | 2 +- zlt-demo/sharding-jdbc-demo/pom.xml | 2 +- zlt-demo/sso-demo/oidc-sso/pom.xml | 2 +- zlt-demo/sso-demo/pom.xml | 2 +- zlt-demo/sso-demo/ss-sso/pom.xml | 2 +- zlt-demo/sso-demo/web-sso/pom.xml | 2 +- zlt-demo/txlcn-demo/pom.xml | 2 +- zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml | 2 +- zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml | 2 +- zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml | 2 +- zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml | 2 +- zlt-gateway/pom.xml | 2 +- zlt-gateway/sc-gateway/pom.xml | 2 +- zlt-job/job-admin/pom.xml | 2 +- zlt-job/job-core/pom.xml | 2 +- zlt-job/job-executor-samples/pom.xml | 2 +- zlt-job/pom.xml | 2 +- zlt-monitor/log-center/pom.xml | 2 +- zlt-monitor/pom.xml | 2 +- zlt-monitor/sc-admin/pom.xml | 2 +- zlt-transaction/pom.xml | 2 +- zlt-transaction/txlcn-tm/pom.xml | 2 +- zlt-uaa/pom.xml | 2 +- zlt-web/back-web/pom.xml | 2 +- zlt-web/pom.xml | 2 +- 60 files changed, 62 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index feb20782..32fd4c39 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # zlt-microservices-platform

- Downloads - Downloads - Downloads + Downloads + Downloads + Downloads Downloads Downloads diff --git a/pom.xml b/pom.xml index 810a253a..d0004a8a 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.zlt central-platform - 5.2.0 + 5.3.0 pom diff --git a/zlt-business/code-generator/pom.xml b/zlt-business/code-generator/pom.xml index b07f6995..a0bdc421 100644 --- a/zlt-business/code-generator/pom.xml +++ b/zlt-business/code-generator/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-business - 5.2.0 + 5.3.0 code-generator diff --git a/zlt-business/file-center/pom.xml b/zlt-business/file-center/pom.xml index 3d2ce3fc..351485ff 100644 --- a/zlt-business/file-center/pom.xml +++ b/zlt-business/file-center/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-business - 5.2.0 + 5.3.0 file-center 文件中心 diff --git a/zlt-business/pom.xml b/zlt-business/pom.xml index 8bfb217e..dffd738b 100644 --- a/zlt-business/pom.xml +++ b/zlt-business/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-business 业务中心 diff --git a/zlt-business/search-center/pom.xml b/zlt-business/search-center/pom.xml index 43752aec..ea8eb12f 100644 --- a/zlt-business/search-center/pom.xml +++ b/zlt-business/search-center/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-business - 5.2.0 + 5.3.0 search-center 搜索中心 diff --git a/zlt-business/search-center/search-client/pom.xml b/zlt-business/search-center/search-client/pom.xml index 2e8a5fa6..9ede2871 100644 --- a/zlt-business/search-center/search-client/pom.xml +++ b/zlt-business/search-center/search-client/pom.xml @@ -4,7 +4,7 @@ com.zlt search-center - 5.2.0 + 5.3.0 search-client 搜索中心客户端 diff --git a/zlt-business/search-center/search-server/pom.xml b/zlt-business/search-center/search-server/pom.xml index 8b33a883..a971e9c6 100644 --- a/zlt-business/search-center/search-server/pom.xml +++ b/zlt-business/search-center/search-server/pom.xml @@ -4,7 +4,7 @@ com.zlt search-center - 5.2.0 + 5.3.0 search-server 搜索中心服务端 diff --git a/zlt-business/user-center/pom.xml b/zlt-business/user-center/pom.xml index a07ee8c1..5a2bce6c 100644 --- a/zlt-business/user-center/pom.xml +++ b/zlt-business/user-center/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-business - 5.2.0 + 5.3.0 user-center 用户中心 diff --git a/zlt-commons/pom.xml b/zlt-commons/pom.xml index eb15b554..cad68d5e 100644 --- a/zlt-commons/pom.xml +++ b/zlt-commons/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-commons 通用组件 diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml b/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml index cf904ec7..5ba6a048 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-common-core/pom.xml b/zlt-commons/zlt-common-core/pom.xml index 78fe81f0..8d0c9467 100644 --- a/zlt-commons/zlt-common-core/pom.xml +++ b/zlt-commons/zlt-common-core/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 zlt-common-core 公共通用组件 diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java index cacb9092..c2d97a8b 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java @@ -10,7 +10,7 @@ public interface CommonConstant { /** * 项目版本号(banner使用) */ - String PROJECT_VERSION = "5.2.0"; + String PROJECT_VERSION = "5.3.0"; /** * token请求头名称 diff --git a/zlt-commons/zlt-common-spring-boot-starter/pom.xml b/zlt-commons/zlt-common-spring-boot-starter/pom.xml index d2118da5..f948cf19 100644 --- a/zlt-commons/zlt-common-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-common-spring-boot-starter/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 zlt-common-spring-boot-starter 公共通用组件 diff --git a/zlt-commons/zlt-db-spring-boot-starter/pom.xml b/zlt-commons/zlt-db-spring-boot-starter/pom.xml index 8b493971..cc8201b0 100644 --- a/zlt-commons/zlt-db-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-db-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml b/zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml index f9383403..4d2bce09 100644 --- a/zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-elasticsearch-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml b/zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml index 925d7d09..8336ea38 100644 --- a/zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-loadbalancer-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-log-spring-boot-starter/pom.xml b/zlt-commons/zlt-log-spring-boot-starter/pom.xml index 69e428da..6ba3e818 100644 --- a/zlt-commons/zlt-log-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-log-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-oss-spring-boot-starter/pom.xml b/zlt-commons/zlt-oss-spring-boot-starter/pom.xml index b68157ec..207c7709 100644 --- a/zlt-commons/zlt-oss-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-oss-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-redis-spring-boot-starter/pom.xml b/zlt-commons/zlt-redis-spring-boot-starter/pom.xml index 212df02e..29fa499f 100644 --- a/zlt-commons/zlt-redis-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-redis-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml b/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml index aed8cf9a..2370b915 100644 --- a/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml b/zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml index e709c4c7..b699bc74 100644 --- a/zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-swagger2-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml b/zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml index 337f5157..601b894a 100644 --- a/zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml +++ b/zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt zlt-commons - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-config/pom.xml b/zlt-config/pom.xml index e5fbb6ca..bd4ed8a4 100644 --- a/zlt-config/pom.xml +++ b/zlt-config/pom.xml @@ -5,7 +5,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 4.0.0 jar diff --git a/zlt-demo/dubbo-demo/pom.xml b/zlt-demo/dubbo-demo/pom.xml index 98132baa..46ef12a8 100644 --- a/zlt-demo/dubbo-demo/pom.xml +++ b/zlt-demo/dubbo-demo/pom.xml @@ -6,7 +6,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 dubbo-demo diff --git a/zlt-demo/pom.xml b/zlt-demo/pom.xml index e3695e9d..93988862 100644 --- a/zlt-demo/pom.xml +++ b/zlt-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-demo pom diff --git a/zlt-demo/rocketmq-demo/pom.xml b/zlt-demo/rocketmq-demo/pom.xml index fd425a90..2fb80a0b 100644 --- a/zlt-demo/rocketmq-demo/pom.xml +++ b/zlt-demo/rocketmq-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 rocketmq-demo pom diff --git a/zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml b/zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml index 5ea764f2..ee15dd55 100644 --- a/zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml +++ b/zlt-demo/rocketmq-demo/rocketmq-consume/pom.xml @@ -4,7 +4,7 @@ com.zlt rocketmq-demo - 5.2.0 + 5.3.0 rocketmq-consume rocketMQ消费者demo diff --git a/zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml b/zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml index 42ceafbd..2201711e 100644 --- a/zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml +++ b/zlt-demo/rocketmq-demo/rocketmq-produce/pom.xml @@ -4,7 +4,7 @@ com.zlt rocketmq-demo - 5.2.0 + 5.3.0 rocketmq-produce rocketMQ生产者demo diff --git a/zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml b/zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml index f4f72160..0973e0e9 100644 --- a/zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml +++ b/zlt-demo/rocketmq-demo/rocketmq-transactional/pom.xml @@ -4,7 +4,7 @@ com.zlt rocketmq-demo - 5.2.0 + 5.3.0 rocketmq-transactional rocketMQ事务消息demo diff --git a/zlt-demo/seata-demo/account-service/pom.xml b/zlt-demo/seata-demo/account-service/pom.xml index 9bc2f2a6..4c5f4143 100644 --- a/zlt-demo/seata-demo/account-service/pom.xml +++ b/zlt-demo/seata-demo/account-service/pom.xml @@ -5,7 +5,7 @@ com.zlt seata-demo - 5.2.0 + 5.3.0 account-service diff --git a/zlt-demo/seata-demo/business-service/pom.xml b/zlt-demo/seata-demo/business-service/pom.xml index 0f17138a..a29e3f52 100644 --- a/zlt-demo/seata-demo/business-service/pom.xml +++ b/zlt-demo/seata-demo/business-service/pom.xml @@ -5,7 +5,7 @@ com.zlt seata-demo - 5.2.0 + 5.3.0 business-service diff --git a/zlt-demo/seata-demo/order-service/pom.xml b/zlt-demo/seata-demo/order-service/pom.xml index 59691833..230e9cba 100644 --- a/zlt-demo/seata-demo/order-service/pom.xml +++ b/zlt-demo/seata-demo/order-service/pom.xml @@ -5,7 +5,7 @@ com.zlt seata-demo - 5.2.0 + 5.3.0 order-service diff --git a/zlt-demo/seata-demo/pom.xml b/zlt-demo/seata-demo/pom.xml index 199abe2c..0a9ced3a 100644 --- a/zlt-demo/seata-demo/pom.xml +++ b/zlt-demo/seata-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 seata-demo seata分布式事务demo diff --git a/zlt-demo/seata-demo/seata-common-starter/pom.xml b/zlt-demo/seata-demo/seata-common-starter/pom.xml index de20f2ef..0a82b22d 100644 --- a/zlt-demo/seata-demo/seata-common-starter/pom.xml +++ b/zlt-demo/seata-demo/seata-common-starter/pom.xml @@ -5,7 +5,7 @@ com.zlt seata-demo - 5.2.0 + 5.3.0 seata-common-starter diff --git a/zlt-demo/seata-demo/storage-service/pom.xml b/zlt-demo/seata-demo/storage-service/pom.xml index 36a5b937..2a524d5c 100644 --- a/zlt-demo/seata-demo/storage-service/pom.xml +++ b/zlt-demo/seata-demo/storage-service/pom.xml @@ -5,7 +5,7 @@ com.zlt seata-demo - 5.2.0 + 5.3.0 storage-service diff --git a/zlt-demo/sharding-jdbc-demo/pom.xml b/zlt-demo/sharding-jdbc-demo/pom.xml index 66576746..f5781259 100644 --- a/zlt-demo/sharding-jdbc-demo/pom.xml +++ b/zlt-demo/sharding-jdbc-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 sharding-jdbc-demo sharding-jdbc分库分表demo diff --git a/zlt-demo/sso-demo/oidc-sso/pom.xml b/zlt-demo/sso-demo/oidc-sso/pom.xml index 4feef845..fd756698 100644 --- a/zlt-demo/sso-demo/oidc-sso/pom.xml +++ b/zlt-demo/sso-demo/oidc-sso/pom.xml @@ -4,7 +4,7 @@ com.zlt sso-demo - 5.2.0 + 5.3.0 oidc-sso OIDC协议单点登录demo diff --git a/zlt-demo/sso-demo/pom.xml b/zlt-demo/sso-demo/pom.xml index 579808b7..b2e0bdb0 100644 --- a/zlt-demo/sso-demo/pom.xml +++ b/zlt-demo/sso-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 sso-demo pom diff --git a/zlt-demo/sso-demo/ss-sso/pom.xml b/zlt-demo/sso-demo/ss-sso/pom.xml index bfa43bf1..bdf85770 100644 --- a/zlt-demo/sso-demo/ss-sso/pom.xml +++ b/zlt-demo/sso-demo/ss-sso/pom.xml @@ -4,7 +4,7 @@ com.zlt sso-demo - 5.2.0 + 5.3.0 ss-sso springSecurity单点登录demo diff --git a/zlt-demo/sso-demo/web-sso/pom.xml b/zlt-demo/sso-demo/web-sso/pom.xml index 3dd5edc4..d1a1984f 100644 --- a/zlt-demo/sso-demo/web-sso/pom.xml +++ b/zlt-demo/sso-demo/web-sso/pom.xml @@ -4,7 +4,7 @@ com.zlt sso-demo - 5.2.0 + 5.3.0 web-sso 前后端分离单点登录demo diff --git a/zlt-demo/txlcn-demo/pom.xml b/zlt-demo/txlcn-demo/pom.xml index 5bcbf5d0..0ce4dae3 100644 --- a/zlt-demo/txlcn-demo/pom.xml +++ b/zlt-demo/txlcn-demo/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-demo - 5.2.0 + 5.3.0 txlcn-demo txlcn分布式事务demo diff --git a/zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml b/zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml index 254b0a53..72ac8d04 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml +++ b/zlt-demo/txlcn-demo/txlcn-demo-common/pom.xml @@ -4,7 +4,7 @@ com.zlt txlcn-demo - 5.2.0 + 5.3.0 txlcn-demo-common demo-common diff --git a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml index 663b3083..bff2f2d7 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml +++ b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-a/pom.xml @@ -3,7 +3,7 @@ com.zlt txlcn-demo - 5.2.0 + 5.3.0 4.0.0 diff --git a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml index e3107053..8877bd4e 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml +++ b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-b/pom.xml @@ -3,7 +3,7 @@ com.zlt txlcn-demo - 5.2.0 + 5.3.0 4.0.0 txlcn-demo-spring-service-b diff --git a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml index 163e8941..ee7f3671 100644 --- a/zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml +++ b/zlt-demo/txlcn-demo/txlcn-demo-spring-service-c/pom.xml @@ -3,7 +3,7 @@ com.zlt txlcn-demo - 5.2.0 + 5.3.0 4.0.0 txlcn-demo-spring-service-c diff --git a/zlt-gateway/pom.xml b/zlt-gateway/pom.xml index e0672140..e58ce502 100644 --- a/zlt-gateway/pom.xml +++ b/zlt-gateway/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-gateway pom diff --git a/zlt-gateway/sc-gateway/pom.xml b/zlt-gateway/sc-gateway/pom.xml index b91045aa..d15fdfd7 100644 --- a/zlt-gateway/sc-gateway/pom.xml +++ b/zlt-gateway/sc-gateway/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-gateway - 5.2.0 + 5.3.0 sc-gateway spring cloud gateway网关 diff --git a/zlt-job/job-admin/pom.xml b/zlt-job/job-admin/pom.xml index 687782b3..102da016 100644 --- a/zlt-job/job-admin/pom.xml +++ b/zlt-job/job-admin/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-job - 5.2.0 + 5.3.0 job-admin jar diff --git a/zlt-job/job-core/pom.xml b/zlt-job/job-core/pom.xml index 05de199d..7a279d19 100644 --- a/zlt-job/job-core/pom.xml +++ b/zlt-job/job-core/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-job - 5.2.0 + 5.3.0 job-core jar diff --git a/zlt-job/job-executor-samples/pom.xml b/zlt-job/job-executor-samples/pom.xml index 8e2f25d0..2a31f63c 100644 --- a/zlt-job/job-executor-samples/pom.xml +++ b/zlt-job/job-executor-samples/pom.xml @@ -6,7 +6,7 @@ com.zlt zlt-job - 5.2.0 + 5.3.0 job-executor-samples jar diff --git a/zlt-job/pom.xml b/zlt-job/pom.xml index 8c57d2b7..60747d33 100644 --- a/zlt-job/pom.xml +++ b/zlt-job/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-job pom diff --git a/zlt-monitor/log-center/pom.xml b/zlt-monitor/log-center/pom.xml index 7003a9cf..87e0bb0c 100644 --- a/zlt-monitor/log-center/pom.xml +++ b/zlt-monitor/log-center/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-monitor - 5.2.0 + 5.3.0 log-center diff --git a/zlt-monitor/pom.xml b/zlt-monitor/pom.xml index 18c88b9a..724bb280 100644 --- a/zlt-monitor/pom.xml +++ b/zlt-monitor/pom.xml @@ -3,7 +3,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-monitor pom diff --git a/zlt-monitor/sc-admin/pom.xml b/zlt-monitor/sc-admin/pom.xml index 5f0ab8fd..e544528b 100644 --- a/zlt-monitor/sc-admin/pom.xml +++ b/zlt-monitor/sc-admin/pom.xml @@ -4,7 +4,7 @@ com.zlt zlt-monitor - 5.2.0 + 5.3.0 sc-admin diff --git a/zlt-transaction/pom.xml b/zlt-transaction/pom.xml index dc57cbd2..9e0140b2 100644 --- a/zlt-transaction/pom.xml +++ b/zlt-transaction/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-transaction 事务 diff --git a/zlt-transaction/txlcn-tm/pom.xml b/zlt-transaction/txlcn-tm/pom.xml index 9e584aee..405b7c43 100644 --- a/zlt-transaction/txlcn-tm/pom.xml +++ b/zlt-transaction/txlcn-tm/pom.xml @@ -3,7 +3,7 @@ com.zlt zlt-transaction - 5.2.0 + 5.3.0 4.0.0 txlcn-tm diff --git a/zlt-uaa/pom.xml b/zlt-uaa/pom.xml index 2567b6a7..fe987f50 100644 --- a/zlt-uaa/pom.xml +++ b/zlt-uaa/pom.xml @@ -4,7 +4,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-uaa 认证中心 diff --git a/zlt-web/back-web/pom.xml b/zlt-web/back-web/pom.xml index c4362f94..d18a4eaf 100644 --- a/zlt-web/back-web/pom.xml +++ b/zlt-web/back-web/pom.xml @@ -6,7 +6,7 @@ com.zlt zlt-web - 5.2.0 + 5.3.0 back-web 后台管理前端 diff --git a/zlt-web/pom.xml b/zlt-web/pom.xml index 726d7cbb..1ea73fdd 100644 --- a/zlt-web/pom.xml +++ b/zlt-web/pom.xml @@ -6,7 +6,7 @@ com.zlt central-platform - 5.2.0 + 5.3.0 zlt-web 前端