Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
普蓝开源社区
盘古开发框架
提交
38fcc5c7
盘古开发框架
项目概览
普蓝开源社区
/
盘古开发框架
通知
25
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
盘古开发框架
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
38fcc5c7
编写于
12月 20, 2021
作者:
X
xiongchun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化pangu-cache-spring-boot-starter 增加分布式锁支持
上级
801f9078
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
307 addition
and
1 deletion
+307
-1
pangu-cache-spring-boot-starter/pom.xml
pangu-cache-spring-boot-starter/pom.xml
+4
-0
pangu-examples/README.md
pangu-examples/README.md
+3
-0
pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties
...ache-single/src/main/resources/application-dev.properties
+1
-1
pangu-examples/pangu-examples-lock-redis-based/.gitignore
pangu-examples/pangu-examples-lock-redis-based/.gitignore
+26
-0
pangu-examples/pangu-examples-lock-redis-based/README.md
pangu-examples/pangu-examples-lock-redis-based/README.md
+5
-0
pangu-examples/pangu-examples-lock-redis-based/pom.xml
pangu-examples/pangu-examples-lock-redis-based/pom.xml
+49
-0
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/LockPanguApplication.java
...anos/pangu/showcases/lock/redis/LockPanguApplication.java
+35
-0
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/AnnotationLockService.java
...u/showcases/lock/redis/service/AnnotationLockService.java
+38
-0
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/ApiLockService.java
...os/pangu/showcases/lock/redis/service/ApiLockService.java
+40
-0
pangu-examples/pangu-examples-lock-redis-based/src/main/resources/application-dev.properties
...redis-based/src/main/resources/application-dev.properties
+27
-0
pangu-examples/pangu-examples-lock-redis-based/src/main/resources/application.properties
...ock-redis-based/src/main/resources/application.properties
+17
-0
pangu-examples/pangu-examples-lock-redis-based/src/test/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/AnnotationLockServiceTest.java
...owcases/lock/redis/service/AnnotationLockServiceTest.java
+32
-0
pangu-examples/pangu-examples-lock-redis-based/src/test/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/ApiLockServiceTest.java
...angu/showcases/lock/redis/service/ApiLockServiceTest.java
+23
-0
pangu-examples/pom.xml
pangu-examples/pom.xml
+1
-0
pangu-parent/pom.xml
pangu-parent/pom.xml
+6
-0
未找到文件。
pangu-cache-spring-boot-starter/pom.xml
浏览文件 @
38fcc5c7
...
...
@@ -52,6 +52,10 @@
<groupId>
com.github.xiaolyuh
</groupId>
<artifactId>
layering-cache-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
lock4j-redis-template-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.aspectj
</groupId>
<artifactId>
aspectjweaver
</artifactId>
...
...
pangu-examples/README.md
浏览文件 @
38fcc5c7
...
...
@@ -29,6 +29,9 @@
-
**pangu-examples-cache-single**
1.
如何使用原生的一级缓存RedisTemplate API
-
**pangu-examples-lock-redis-based**
1.
如何使用基于Redis的分布式锁(注解式、API式)
-
**pangu-examples-dubbo-api**
1.
开发Dubbo服务时接口文件和POJO相关类的打包模块
...
...
pangu-examples/pangu-examples-cache-single/src/main/resources/application-dev.properties
浏览文件 @
38fcc5c7
...
...
@@ -16,7 +16,7 @@
#
spring.application.name
=
pangu-examples-cache-single
# spring-
cache
\u4E00\u7EA7\u7F13\u5B58
# spring-
redis
\u4E00\u7EA7\u7F13\u5B58
spring.redis.host
=
localhost
spring.redis.database
=
1
spring.redis.port
=
6379
...
...
pangu-examples/pangu-examples-lock-redis-based/.gitignore
0 → 100644
浏览文件 @
38fcc5c7
/target/
/bin/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
pangu-examples/pangu-examples-lock-redis-based/README.md
0 → 100644
浏览文件 @
38fcc5c7
#### :mushroom: 本范例演示功能
1.
如何使用基于Redis的分布式锁(注解式、API式)。
**更多开发指南请参考盘古平台相关文档说明。**
\ No newline at end of file
pangu-examples/pangu-examples-lock-redis-based/pom.xml
0 → 100644
浏览文件 @
38fcc5c7
<?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"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.gitee.pulanos.pangu
</groupId>
<artifactId>
pangu-parent
</artifactId>
<version>
5.0.7
</version>
<relativePath/>
</parent>
<groupId>
com.gitee.pulanos.pangu
</groupId>
<artifactId>
pangu-examples-lock-redis-based
</artifactId>
<packaging>
jar
</packaging>
<version>
1.0.0
</version>
<dependencies>
<dependency>
<groupId>
com.gitee.pulanos.pangu
</groupId>
<artifactId>
pangu-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.gitee.pulanos.pangu
</groupId>
<artifactId>
pangu-cache-spring-boot-starter
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${spring-boot-maven-plugin.version}
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
${maven-compiler-plugin.version}
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/LockPanguApplication.java
0 → 100644
浏览文件 @
38fcc5c7
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.gitee.pulanos.pangu.showcases.lock.redis
;
import
com.gitee.pulanos.pangu.framework.starter.PanGuApplicationBuilder
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* @author xiongchun
*/
@Slf4j
@SpringBootApplication
public
class
LockPanguApplication
{
public
static
void
main
(
String
[]
args
)
{
PanGuApplicationBuilder
.
init
(
LockPanguApplication
.
class
).
run
(
args
);
}
}
\ No newline at end of file
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/AnnotationLockService.java
0 → 100644
浏览文件 @
38fcc5c7
package
com.gitee.pulanos.pangu.showcases.lock.redis.service
;
import
cn.hutool.core.thread.ThreadUtil
;
import
com.baomidou.lock.annotation.Lock4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
/**
* 基于注解方式的分布式锁
*
* @author xiongchun
*/
@Slf4j
@Component
public
class
AnnotationLockService
{
/**
* 默认获取锁超时3秒,30秒锁过期
*/
@Lock4j
public
void
doBiz
()
{
log
.
info
(
"执行doBiz..."
);
ThreadUtil
.
sleep
(
25
*
1000
);
}
/**
* 配置获取锁超时时间和锁过期时间 支持SPEL
* @param accountId
*/
@Lock4j
(
keys
=
{
"#accountId"
},
expire
=
20000
,
acquireTimeout
=
10000
)
public
void
doBiz2
(
Long
accountId
)
{
log
.
info
(
"执行doBiz2..."
);
ThreadUtil
.
sleep
(
20
*
1000
);
}
}
pangu-examples/pangu-examples-lock-redis-based/src/main/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/ApiLockService.java
0 → 100644
浏览文件 @
38fcc5c7
package
com.gitee.pulanos.pangu.showcases.lock.redis.service
;
import
cn.hutool.core.thread.ThreadUtil
;
import
com.baomidou.lock.LockInfo
;
import
com.baomidou.lock.LockTemplate
;
import
com.baomidou.lock.exception.LockException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 基于API方式的分布式锁
*
* @author xiongchun
*/
@Slf4j
@Component
public
class
ApiLockService
{
@Autowired
private
LockTemplate
lockTemplate
;
public
void
apiLock
(
String
userId
)
{
//... 各种不需要上锁的操作
String
lockKey
=
"lock4j:ApiLockService:apiLock:"
+
userId
;
final
LockInfo
lockInfo
=
lockTemplate
.
lock
(
lockKey
);
//申请锁失败
if
(
null
==
lockInfo
)
{
throw
new
LockException
(
"业务处理中,请稍后再试..."
);
}
//申请锁成功
try
{
ThreadUtil
.
sleep
(
10000L
);
log
.
info
(
"执行apiLock, 当前线程{}"
,
Thread
.
currentThread
().
getName
());
}
finally
{
lockTemplate
.
releaseLock
(
lockInfo
);
}
}
}
pangu-examples/pangu-examples-lock-redis-based/src/main/resources/application-dev.properties
0 → 100644
浏览文件 @
38fcc5c7
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
spring.application.name
=
pangu-examples-lock-redis-based
# spring-redis
spring.redis.host
=
localhost
spring.redis.database
=
1
spring.redis.port
=
6379
spring.redis.password
=
logging.level.root
=
INFO
logging.level.com.gitee.pulanos.pangu
=
INFO
logging.level.com.baomidou.lock
=
DEBUG
\ No newline at end of file
pangu-examples/pangu-examples-lock-redis-based/src/main/resources/application.properties
0 → 100644
浏览文件 @
38fcc5c7
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
spring.profiles.active
=
${spring.profiles.active:dev}
\ No newline at end of file
pangu-examples/pangu-examples-lock-redis-based/src/test/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/AnnotationLockServiceTest.java
0 → 100644
浏览文件 @
38fcc5c7
package
com.gitee.pulanos.pangu.showcases.lock.redis.service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
junit
.
Assert
.*;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
AnnotationLockServiceTest
{
@Autowired
private
AnnotationLockService
annotationLockService
;
@Test
public
void
doBiz
()
{
annotationLockService
.
doBiz
();
}
@Test
public
void
doBizAgain
()
{
annotationLockService
.
doBiz
();
}
@Test
public
void
doBiz2
()
{
annotationLockService
.
doBiz2
(
100L
);
}
}
\ No newline at end of file
pangu-examples/pangu-examples-lock-redis-based/src/test/java/com/gitee/pulanos/pangu/showcases/lock/redis/service/ApiLockServiceTest.java
0 → 100644
浏览文件 @
38fcc5c7
package
com.gitee.pulanos.pangu.showcases.lock.redis.service
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
junit
.
Assert
.*;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
ApiLockServiceTest
{
@Autowired
private
ApiLockService
apiLockService
;
@Test
public
void
apiLock
()
{
apiLockService
.
apiLock
(
"1000"
);
}
}
\ No newline at end of file
pangu-examples/pom.xml
浏览文件 @
38fcc5c7
...
...
@@ -19,6 +19,7 @@
<module>
pangu-examples-crud
</module>
<module>
pangu-examples-cache-single
</module>
<module>
pangu-examples-cache-layering
</module>
<module>
pangu-examples-lock-redis-based
</module>
<module>
pangu-examples-dubbo-api
</module>
<module>
pangu-examples-dubbo-service
</module>
<module>
pangu-examples-dubbo-consumer
</module>
...
...
pangu-parent/pom.xml
浏览文件 @
38fcc5c7
...
...
@@ -52,6 +52,7 @@
<nacos-config-spring-boot-starter.version>
0.2.7
</nacos-config-spring-boot-starter.version>
<nacos-config-spring-boot-actuator.version>
0.2.7
</nacos-config-spring-boot-actuator.version>
<mybatis-plus.version>
3.4.3.2
</mybatis-plus.version>
<lock4j.version>
2.2.1
</lock4j.version>
<shenyu.version>
2.4.1
</shenyu.version>
<layering-cache.version>
3.3.4
</layering-cache.version>
<mysql-connector-java.version>
8.0.26
</mysql-connector-java.version>
...
...
@@ -135,6 +136,11 @@
<artifactId>
mybatis-plus-boot-starter
</artifactId>
<version>
${mybatis-plus.version}
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
lock4j-redis-template-spring-boot-starter
</artifactId>
<version>
${lock4j.version}
</version>
</dependency>
<dependency>
<groupId>
com.github.xiaolyuh
</groupId>
<artifactId>
layering-cache-starter
</artifactId>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录