Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
4598e974
Commit
4598e974
authored
Jan 03, 2023
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改bug
parent
377045ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
96 deletions
+143
-96
RedissonConfig.java
...java/com/yeejoin/amos/boot/biz/config/RedissonConfig.java
+34
-24
TimeLineController.java
...join/amos/fas/business/controller/TimeLineController.java
+3
-1
FireScheduled.java
...om/yeejoin/amos/fas/business/scheduled/FireScheduled.java
+106
-71
No files found.
amos-boot-biz-common/src/main/java/com/yeejoin/amos/boot/biz/config/RedissonConfig.java
View file @
4598e974
package
com
.
yeejoin
.
amos
.
boot
.
biz
.
config
;
package
com
.
yeejoin
.
amos
.
boot
.
biz
.
config
;
import
com.sun.org.apache.regexp.internal.RE
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.redisson.Redisson
;
import
org.redisson.Redisson
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
...
@@ -23,6 +24,8 @@ import java.util.List;
...
@@ -23,6 +24,8 @@ import java.util.List;
public
class
RedissonConfig
{
public
class
RedissonConfig
{
@Autowired
@Autowired
private
RedisConfigProperties
redisConfigProperties
;
private
RedisConfigProperties
redisConfigProperties
;
private
volatile
static
RedissonClient
redissonClient
;
/**
/**
* 集群模式的 redisson 客户端
* 集群模式的 redisson 客户端
*
*
...
@@ -31,32 +34,39 @@ public class RedissonConfig {
...
@@ -31,32 +34,39 @@ public class RedissonConfig {
@Bean
@Bean
@ConditionalOnProperty
(
name
=
"spring.redis.mode"
,
havingValue
=
"cluster"
)
@ConditionalOnProperty
(
name
=
"spring.redis.mode"
,
havingValue
=
"cluster"
)
public
RedissonClient
redissonClient
()
{
public
RedissonClient
redissonClient
()
{
//redisson版本是3.5,集群的ip前面要加上“redis://”,不然会报错,3.2版本可不加
if
(
redissonClient
==
null
){
List
<
String
>
clusterNodes
=
new
ArrayList
<>();
synchronized
(
RedissonConfig
.
class
){
System
.
out
.
println
(
"cluster redisProperties:"
+
redisConfigProperties
.
getCluster
().
toString
());
if
(
redissonClient
==
null
){
for
(
int
i
=
0
;
i
<
redisConfigProperties
.
getCluster
().
getNodes
().
size
();
i
++)
{
//redisson版本是3.5,集群的ip前面要加上“redis://”,不然会报错,3.2版本可不加
clusterNodes
.
add
(
"redis://"
+
redisConfigProperties
.
getCluster
().
getNodes
().
get
(
i
));
List
<
String
>
clusterNodes
=
new
ArrayList
<>();
}
System
.
out
.
println
(
"cluster redisProperties:"
+
redisConfigProperties
.
getCluster
().
toString
());
Config
config
=
new
Config
();
for
(
int
i
=
0
;
i
<
redisConfigProperties
.
getCluster
().
getNodes
().
size
();
i
++)
{
clusterNodes
.
add
(
"redis://"
+
redisConfigProperties
.
getCluster
().
getNodes
().
get
(
i
));
}
Config
config
=
new
Config
();
ClusterServersConfig
clusterServersConfig
=
config
.
useClusterServers
()
//设置集群扫描时间
.
setScanInterval
(
5000
)
// 集群状态扫描间隔时间,单位是毫秒
.
setTimeout
(
30000
)
//主节点线程池数量
.
setMasterConnectionPoolSize
(
20
)
//从节点线程池数量
.
setSlaveConnectionPoolSize
(
20
)
.
setIdleConnectionTimeout
(
10000
)
.
setSlaveConnectionMinimumIdleSize
(
20
)
.
setMasterConnectionMinimumIdleSize
(
20
)
.
addNodeAddress
(
clusterNodes
.
toArray
(
new
String
[
clusterNodes
.
size
()]));
clusterServersConfig
.
setCheckSlotsCoverage
(
false
);
// 设置密码
if
(
StringUtils
.
isNotBlank
(
redisConfigProperties
.
getPassword
()))
{
clusterServersConfig
.
setPassword
(
redisConfigProperties
.
getPassword
());
}
redissonClient
=
Redisson
.
create
(
config
);
ClusterServersConfig
clusterServersConfig
=
config
.
useClusterServers
()
}
//设置集群扫描时间
}
.
setScanInterval
(
5000
)
// 集群状态扫描间隔时间,单位是毫秒
.
setTimeout
(
30000
)
//主节点线程池数量
.
setMasterConnectionPoolSize
(
20
)
//从节点线程池数量
.
setSlaveConnectionPoolSize
(
20
)
.
setIdleConnectionTimeout
(
10000
)
.
setSlaveConnectionMinimumIdleSize
(
20
)
.
setMasterConnectionMinimumIdleSize
(
20
)
.
addNodeAddress
(
clusterNodes
.
toArray
(
new
String
[
clusterNodes
.
size
()]));
clusterServersConfig
.
setCheckSlotsCoverage
(
false
);
// 设置密码
if
(
StringUtils
.
isNotBlank
(
redisConfigProperties
.
getPassword
()))
{
clusterServersConfig
.
setPassword
(
redisConfigProperties
.
getPassword
());
}
}
RedissonClient
redissonClient
=
Redisson
.
create
(
config
);
return
redissonClient
;
return
redissonClient
;
}
}
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-fas-biz/src/main/java/com/yeejoin/amos/fas/business/controller/TimeLineController.java
View file @
4598e974
...
@@ -97,7 +97,9 @@ public class TimeLineController extends AbstractBaseController{
...
@@ -97,7 +97,9 @@ public class TimeLineController extends AbstractBaseController{
map
.
put
(
"stepState"
,
stepState
);
map
.
put
(
"stepState"
,
stepState
);
map
.
put
(
"token"
,
getToken
());
map
.
put
(
"token"
,
getToken
());
map
.
put
(
"product"
,
getProduct
());
map
.
put
(
"product"
,
getProduct
());
FireScheduled
.
getFireQueue
().
addLast
(
map
);
map
.
put
(
"appKey"
,
getAppKey
());
//fireScheduled.getFireQueue().addLast(map);
fireScheduled
.
runFireQueue
(
map
);
return
CommonResponseUtil
.
success
(
"SUCCESS"
);
return
CommonResponseUtil
.
success
(
"SUCCESS"
);
}
}
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-fas-biz/src/main/java/com/yeejoin/amos/fas/business/scheduled/FireScheduled.java
View file @
4598e974
...
@@ -13,16 +13,19 @@ import org.slf4j.Logger;
...
@@ -13,16 +13,19 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance
;
import
com.yeejoin.amos.fas.business.service.intfc.IContingencyInstance
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
@Component
@Component
public
class
FireScheduled
{
public
class
FireScheduled
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
FireScheduled
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
FireScheduled
.
class
);
private
static
LinkedList
<
Map
<
String
,
String
>>
fireQueue
=
new
LinkedList
<>();
//
private static LinkedList<Map<String, String>> fireQueue = new LinkedList<>();
@Autowired
@Autowired
IContingencyInstance
iContingencyInstance
;
IContingencyInstance
iContingencyInstance
;
...
@@ -33,87 +36,119 @@ public class FireScheduled {
...
@@ -33,87 +36,119 @@ public class FireScheduled {
@Value
(
"${spring.redis.mode}"
)
@Value
(
"${spring.redis.mode}"
)
private
String
cluster
;
private
String
cluster
;
@Scheduled
(
cron
=
"*/2 * * * * ?"
)
// @Scheduled(cron = "*/2 * * * * ?")
public
void
runFireQueue
()
throws
Exception
{
// public void runFireQueue() throws Exception {
//
if
(
"cluster"
.
equals
(
cluster
)){
// if("cluster".equals(cluster)){
//
DateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String
time
=
format
.
format
(
new
Date
());
// String time=format.format(new Date());
String
jobName
=
"fas-1"
+
time
;
// String jobName = "fas-1" + time;
//
//
RLock
lock
=
redisson
.
getLock
(
jobName
);
// RLock lock = redisson.getLock(jobName);
try
{
// try {
//拿锁失败10停止尝试, 任务执行超时默认续30s 每个10秒续到30
// //拿锁失败10停止尝试, 任务执行超时默认续30s 每个10秒续到30
lock
.
tryLock
(
10
,
TimeUnit
.
SECONDS
);
// lock.tryLock(10, TimeUnit.SECONDS);
System
.
out
.
println
(
"获取锁成功============"
);
// System.out.println("获取锁成功============");
//为了防止重复
// //为了防止重复
if
(!
redisUtils
.
hasKey
(
jobName
+
"_redisson_key"
))
{
// if (!redisUtils.hasKey(jobName + "_redisson_key")) {
redisUtils
.
set
(
jobName
+
"_redisson_key"
,
"1"
);
//
// redisUtils.set(jobName + "_redisson_key", "1");//
//
//
if
(
fireQueue
.
size
()
==
0
)
// if (fireQueue.size() == 0)
return
;
// return;
//
Map
<
String
,
String
>
map
=
fireQueue
.
getFirst
();
// Map<String, String> map = fireQueue.getFirst();
String
batchNo
=
map
.
get
(
"batchNo"
);
// String batchNo = map.get("batchNo");
String
stepCode
=
map
.
get
(
"stepCode"
);
// String stepCode = map.get("stepCode");
String
buttonCode
=
map
.
get
(
"buttonCode"
);
// String buttonCode = map.get("buttonCode");
String
confirm
=
map
.
get
(
"confirm"
);
// String confirm = map.get("confirm");
String
contingencyPlanId
=
map
.
get
(
"contingencyPlanId"
);
// String contingencyPlanId = map.get("contingencyPlanId");
String
stepState
=
map
.
get
(
"stepState"
);
// String stepState = map.get("stepState");
// String token = map.get("token");
//// String token = map.get("token");
// String product = map.get("product");
//// String product = map.get("product");
//
log
.
info
(
"fireQueue-size:"
+
fireQueue
.
size
());
// log.info("fireQueue-size:" + fireQueue.size());
log
.
info
(
"stepCode:"
+
map
.
get
(
"stepCode"
));
// log.info("stepCode:" + map.get("stepCode"));
log
.
info
(
"buttonCode:"
+
map
.
get
(
"buttonCode"
));
// log.info("buttonCode:" + map.get("buttonCode"));
log
.
info
(
"confirm:"
+
map
.
get
(
"confirm"
));
// log.info("confirm:" + map.get("confirm"));
log
.
info
(
"stepState:"
+
map
.
get
(
"stepState"
));
// log.info("stepState:" + map.get("stepState"));
// RequestContext.setToken(token);
//// RequestContext.setToken(token);
// RequestContext.setProduct(product);
//// RequestContext.setProduct(product);
iContingencyInstance
.
setButtonExecuted
(
batchNo
,
contingencyPlanId
,
buttonCode
,
confirm
);
// iContingencyInstance.setButtonExecuted(batchNo, contingencyPlanId, buttonCode, confirm);
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
);
// iContingencyInstance.fire(batchNo, stepCode, contingencyPlanId, buttonCode, confirm, stepState);
}
// }
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
throw
e
;
// throw e;
}
finally
{
// } finally {
fireQueue
.
removeFirst
();
// fireQueue.removeFirst();
lock
.
unlock
();
//释放锁
// lock.unlock(); //释放锁
//
}
// }
}
else
{
// }else{
//
if
(
fireQueue
.
size
()
==
0
)
// if (fireQueue.size() == 0)
return
;
// return;
//
Map
<
String
,
String
>
map
=
fireQueue
.
getFirst
();
// Map<String, String> map = fireQueue.getFirst();
// String batchNo = map.get("batchNo");
// String stepCode = map.get("stepCode");
// String buttonCode = map.get("buttonCode");
// String confirm = map.get("confirm");
// String contingencyPlanId = map.get("contingencyPlanId");
// String stepState = map.get("stepState");
//// String token = map.get("token");
//// String product = map.get("product");
//
// log.info("fireQueue-size:" + fireQueue.size());
// log.info("stepCode:" + map.get("stepCode"));
// log.info("buttonCode:" + map.get("buttonCode"));
// log.info("confirm:" + map.get("confirm"));
// log.info("stepState:" + map.get("stepState"));
//// RequestContext.setToken(token);
//// RequestContext.setProduct(product);
// iContingencyInstance.setButtonExecuted(batchNo, contingencyPlanId, buttonCode, confirm);
// iContingencyInstance.fire(batchNo, stepCode, contingencyPlanId, buttonCode, confirm, stepState);
// }
// }
// public static LinkedList<Map<String, String>> getFireQueue() {
// return fireQueue;
// }
// public static void setFireQueue(LinkedList<Map<String, String>> fireQueue) {
// FireScheduled.fireQueue = fireQueue;
// }
@Async
public
void
runFireQueue
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
batchNo
=
map
.
get
(
"batchNo"
);
String
batchNo
=
map
.
get
(
"batchNo"
);
String
stepCode
=
map
.
get
(
"stepCode"
);
String
stepCode
=
map
.
get
(
"stepCode"
);
String
buttonCode
=
map
.
get
(
"buttonCode"
);
String
buttonCode
=
map
.
get
(
"buttonCode"
);
String
confirm
=
map
.
get
(
"confirm"
);
String
confirm
=
map
.
get
(
"confirm"
);
String
contingencyPlanId
=
map
.
get
(
"contingencyPlanId"
);
String
contingencyPlanId
=
map
.
get
(
"contingencyPlanId"
);
String
stepState
=
map
.
get
(
"stepState"
);
String
stepState
=
map
.
get
(
"stepState"
);
// String token = map.get("token");
String
token
=
map
.
get
(
"token"
);
// String product = map.get("product");
String
product
=
map
.
get
(
"product"
);
String
appKey
=
map
.
get
(
"appKey"
);
log
.
info
(
"fireQueue-size:"
+
fireQueue
.
size
());
log
.
info
(
"stepCode:"
+
map
.
get
(
"stepCode"
));
log
.
info
(
"stepCode:"
+
map
.
get
(
"stepCode"
));
log
.
info
(
"buttonCode:"
+
map
.
get
(
"buttonCode"
));
log
.
info
(
"buttonCode:"
+
map
.
get
(
"buttonCode"
));
log
.
info
(
"confirm:"
+
map
.
get
(
"confirm"
));
log
.
info
(
"confirm:"
+
map
.
get
(
"confirm"
));
log
.
info
(
"stepState:"
+
map
.
get
(
"stepState"
));
log
.
info
(
"stepState:"
+
map
.
get
(
"stepState"
));
// RequestContext.setToken(token);
RequestContext
.
setToken
(
token
);
// RequestContext.setProduct(product);
RequestContext
.
setProduct
(
product
);
RequestContext
.
setProduct
(
appKey
);
iContingencyInstance
.
setButtonExecuted
(
batchNo
,
contingencyPlanId
,
buttonCode
,
confirm
);
iContingencyInstance
.
setButtonExecuted
(
batchNo
,
contingencyPlanId
,
buttonCode
,
confirm
);
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
);
iContingencyInstance
.
fire
(
batchNo
,
stepCode
,
contingencyPlanId
,
buttonCode
,
confirm
,
stepState
);
}
}
public
static
LinkedList
<
Map
<
String
,
String
>>
getFireQueue
()
{
return
fireQueue
;
}
public
static
void
setFireQueue
(
LinkedList
<
Map
<
String
,
String
>>
fireQueue
)
{
FireScheduled
.
fireQueue
=
fireQueue
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment