Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
9f5b5d1c
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9f5b5d1c
编写于
4月 03, 2021
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增zookeeper-starter实现zookeeper分布式锁
上级
0ce8b4d6
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
223 addition
and
6 deletion
+223
-6
README.md
README.md
+3
-0
pom.xml
pom.xml
+16
-0
zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java
...rc/main/java/com/central/file/service/impl/S3Service.java
+2
-3
zlt-business/user-center/pom.xml
zlt-business/user-center/pom.xml
+4
-0
zlt-commons/pom.xml
zlt-commons/pom.xml
+1
-0
zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java
...main/java/com/central/common/constant/CommonConstant.java
+6
-1
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedissonDistributedLock.java
...om/central/common/redis/lock/RedissonDistributedLock.java
+2
-2
zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml
zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml
+31
-0
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/ZookeeperAutoConfiguration.java
.../central/common/zookeeper/ZookeeperAutoConfiguration.java
+40
-0
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/lock/ZookeeperDistributedLock.java
...ntral/common/zookeeper/lock/ZookeeperDistributedLock.java
+71
-0
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/properties/ZookeeperProperty.java
...entral/common/zookeeper/properties/ZookeeperProperty.java
+45
-0
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/resources/META-INF/spring.factories
...boot-starter/src/main/resources/META-INF/spring.factories
+2
-0
未找到文件。
README.md
浏览文件 @
9f5b5d1c
...
...
@@ -81,6 +81,9 @@ central-platform -- 父项目,公共依赖
│
│
├─
zlt
-
ribbon
-
spring
-
boot
-
starter
-- 封装Ribbon和Feign的通用操作逻辑
│
│
├─
zlt
-
sentinel
-
spring
-
boot
-
starter
-- 封装Sentinel的通用操作逻辑
│
│
├─
zlt
-
swagger2
-
spring
-
boot
-
starter
-- 封装Swagger通用操作逻辑
│
│
├─
zlt
-
elasticsearch
-
spring
-
boot
-
starter
-- 封装Elasticsearch通用操作逻辑
│
│
├─
zlt
-
oss
-
spring
-
boot
-
starter
-- 封装对象存储通用操作逻辑
│
│
├─
zlt
-
zookeeper
-
spring
-
boot
-
starter
-- 封装Zookeeper通用操作逻辑
│
├─
zlt
-
config
-- 配置中心
│
├─
zlt
-
doc
-- 项目文档
│
├─
zlt
-
gateway
-- api网关一级工程
...
...
pom.xml
浏览文件 @
9f5b5d1c
...
...
@@ -52,6 +52,7 @@
<knife4j.version>
2.0.5
</knife4j.version>
<hibernate-validator.version>
6.2.0.Final
</hibernate-validator.version>
<dubbo.version>
2.7.8
</dubbo.version>
<curator.version>
5.1.0
</curator.version>
<docker-maven-plugin.version>
1.2.2
</docker-maven-plugin.version>
<sonar.exclusions>
zlt-job/**/*, zlt-register/**/*, zlt-web/**/*
</sonar.exclusions>
<docker.baseImage>
openjdk:8-jre-alpine
</docker.baseImage>
...
...
@@ -355,6 +356,21 @@
<artifactId>
zlt-oss-spring-boot-starter
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-zookeeper-spring-boot-starter
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-recipes
</artifactId>
<version>
${curator.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-framework
</artifactId>
<version>
${curator.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
zlt-business/file-center/src/main/java/com/central/file/service/impl/S3Service.java
浏览文件 @
9f5b5d1c
package
com.central.file.service.impl
;
import
cn.hutool.core.util.StrUtil
;
import
com.central.common.constant.CommonConstant
;
import
com.central.file.model.FileInfo
;
import
com.central.oss.model.ObjectInfo
;
import
com.central.oss.properties.FileServerProperties
;
...
...
@@ -24,8 +25,6 @@ import java.io.OutputStream;
@Service
@ConditionalOnProperty
(
prefix
=
com
.
central
.
oss
.
properties
.
FileServerProperties
.
PREFIX
,
name
=
"type"
,
havingValue
=
FileServerProperties
.
TYPE_S3
)
public
class
S3Service
extends
AbstractIFileService
{
private
static
final
String
PATH_SPLIT
=
"/"
;
@Resource
private
S3Template
s3Template
;
...
...
@@ -64,7 +63,7 @@ public class S3Service extends AbstractIFileService {
private
S3Object
parsePath
(
String
path
)
{
S3Object
s3Object
=
new
S3Object
();
if
(
StrUtil
.
isNotEmpty
(
path
))
{
int
splitIndex
=
path
.
lastIndexOf
(
PATH_SPLIT
);
int
splitIndex
=
path
.
lastIndexOf
(
CommonConstant
.
PATH_SPLIT
);
if
(
splitIndex
!=
-
1
)
{
s3Object
.
bucketName
=
path
.
substring
(
0
,
splitIndex
);
s3Object
.
objectName
=
path
.
substring
(
splitIndex
+
1
);
...
...
zlt-business/user-center/pom.xml
浏览文件 @
9f5b5d1c
...
...
@@ -43,6 +43,10 @@
<groupId>
com.zlt
</groupId>
<artifactId>
search-client
</artifactId>
</dependency>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-zookeeper-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
zlt-commons/pom.xml
浏览文件 @
9f5b5d1c
...
...
@@ -22,5 +22,6 @@
<module>
zlt-common-core
</module>
<module>
zlt-elasticsearch-spring-boot-starter
</module>
<module>
zlt-oss-spring-boot-starter
</module>
<module>
zlt-zookeeper-spring-boot-starter
</module>
</modules>
</project>
\ No newline at end of file
zlt-commons/zlt-common-core/src/main/java/com/central/common/constant/CommonConstant.java
浏览文件 @
9f5b5d1c
...
...
@@ -102,7 +102,7 @@ public interface CommonConstant {
String
DEF_USER_PASSWORD
=
"123456"
;
String
LOCK_KEY_PREFIX
=
"LOCK_KEY
:
"
;
String
LOCK_KEY_PREFIX
=
"LOCK_KEY"
;
/**
* 租户id参数
...
...
@@ -126,4 +126,9 @@ public interface CommonConstant {
* 注册中心元数据 版本号
*/
String
METADATA_VERSION
=
"version"
;
/**
* 文件分隔符
*/
String
PATH_SPLIT
=
"/"
;
}
zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/lock/RedissonDistributedLock.java
浏览文件 @
9f5b5d1c
...
...
@@ -32,9 +32,9 @@ public class RedissonDistributedLock implements DistributedLock {
private
ZLock
getLock
(
String
key
,
boolean
isFair
)
{
RLock
lock
;
if
(
isFair
)
{
lock
=
redisson
.
getFairLock
(
CommonConstant
.
LOCK_KEY_PREFIX
+
key
);
lock
=
redisson
.
getFairLock
(
CommonConstant
.
LOCK_KEY_PREFIX
+
":"
+
key
);
}
else
{
lock
=
redisson
.
getLock
(
CommonConstant
.
LOCK_KEY_PREFIX
+
key
);
lock
=
redisson
.
getLock
(
CommonConstant
.
LOCK_KEY_PREFIX
+
":"
+
key
);
}
return
new
ZLock
(
lock
,
this
);
}
...
...
zlt-commons/zlt-zookeeper-spring-boot-starter/pom.xml
0 → 100644
浏览文件 @
9f5b5d1c
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-commons
</artifactId>
<version>
4.3.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
jar
</packaging>
<artifactId>
zlt-zookeeper-spring-boot-starter
</artifactId>
<description>
zookeeper通用组件
</description>
<dependencies>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-common-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-recipes
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</project>
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/ZookeeperAutoConfiguration.java
0 → 100644
浏览文件 @
9f5b5d1c
package
com.central.common.zookeeper
;
import
com.central.common.zookeeper.properties.ZookeeperProperty
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.CuratorFrameworkFactory
;
import
org.apache.curator.retry.ExponentialBackoffRetry
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
/**
* redis 配置类
*
* @author zlt
* @version 1.0
* @date 2021/4/3
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@EnableConfigurationProperties
(
ZookeeperProperty
.
class
)
@ComponentScan
public
class
ZookeeperAutoConfiguration
{
/**
* 初始化连接
*/
@Bean
(
initMethod
=
"start"
,
destroyMethod
=
"close"
)
@ConditionalOnMissingBean
public
CuratorFramework
curatorFramework
(
ZookeeperProperty
property
)
{
RetryPolicy
retryPolicy
=
new
ExponentialBackoffRetry
(
property
.
getBaseSleepTime
(),
property
.
getMaxRetries
());
return
CuratorFrameworkFactory
.
builder
()
.
connectString
(
property
.
getConnectString
())
.
connectionTimeoutMs
(
property
.
getConnectionTimeout
())
.
sessionTimeoutMs
(
property
.
getSessionTimeout
())
.
retryPolicy
(
retryPolicy
)
.
build
();
}
}
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/lock/ZookeeperDistributedLock.java
0 → 100644
浏览文件 @
9f5b5d1c
package
com.central.common.zookeeper.lock
;
import
com.central.common.constant.CommonConstant
;
import
com.central.common.exception.LockException
;
import
com.central.common.lock.DistributedLock
;
import
com.central.common.lock.ZLock
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.recipes.locks.InterProcessMutex
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.concurrent.TimeUnit
;
/**
* zookeeper分布式锁实现
*
* @author zlt
* @version 1.0
* @date 2021/4/3
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Component
@ConditionalOnProperty
(
prefix
=
"zlt.lock"
,
name
=
"lockerType"
,
havingValue
=
"ZK"
)
public
class
ZookeeperDistributedLock
implements
DistributedLock
{
@Resource
private
CuratorFramework
client
;
private
ZLock
getLock
(
String
key
)
{
InterProcessMutex
lock
=
new
InterProcessMutex
(
client
,
getPath
(
key
));
return
new
ZLock
(
lock
,
this
);
}
@Override
public
ZLock
lock
(
String
key
,
long
leaseTime
,
TimeUnit
unit
,
boolean
isFair
)
throws
Exception
{
ZLock
zLock
=
this
.
getLock
(
key
);
InterProcessMutex
ipm
=
(
InterProcessMutex
)
zLock
.
getLock
();
ipm
.
acquire
();
return
zLock
;
}
@Override
public
ZLock
tryLock
(
String
key
,
long
waitTime
,
long
leaseTime
,
TimeUnit
unit
,
boolean
isFair
)
throws
Exception
{
ZLock
zLock
=
this
.
getLock
(
key
);
InterProcessMutex
ipm
=
(
InterProcessMutex
)
zLock
.
getLock
();
if
(
ipm
.
acquire
(
waitTime
,
unit
))
{
return
zLock
;
}
return
null
;
}
@Override
public
void
unlock
(
Object
lock
)
throws
Exception
{
if
(
lock
!=
null
)
{
if
(
lock
instanceof
InterProcessMutex
)
{
InterProcessMutex
ipm
=
(
InterProcessMutex
)
lock
;
if
(
ipm
.
isAcquiredInThisProcess
())
{
ipm
.
release
();
}
}
else
{
throw
new
LockException
(
"requires InterProcessMutex type"
);
}
}
}
private
String
getPath
(
String
key
)
{
return
CommonConstant
.
PATH_SPLIT
+
CommonConstant
.
LOCK_KEY_PREFIX
+
CommonConstant
.
PATH_SPLIT
+
key
;
}
}
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/java/com/central/common/zookeeper/properties/ZookeeperProperty.java
0 → 100644
浏览文件 @
9f5b5d1c
package
com.central.common.zookeeper.properties
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* zookeeper配置
*
* @author zlt
* @version 1.0
* @date 2021/4/3
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Setter
@Getter
@ConfigurationProperties
(
prefix
=
"zlt.zookeeper"
)
public
class
ZookeeperProperty
{
/**
* zk连接集群,多个用逗号隔开
*/
private
String
connectString
;
/**
* 会话超时时间(毫秒)
*/
private
int
sessionTimeout
=
15000
;
/**
* 连接超时时间(毫秒)
*/
private
int
connectionTimeout
=
15000
;
/**
* 初始重试等待时间(毫秒)
*/
private
int
baseSleepTime
=
2000
;
/**
* 重试最大次数
*/
private
int
maxRetries
=
10
;
}
zlt-commons/zlt-zookeeper-spring-boot-starter/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
9f5b5d1c
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.central.common.zookeeper.ZookeeperAutoConfiguration
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录