Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
3699a00a
Commit
3699a00a
authored
Jul 12, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0.0
parent
59e3e981
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
231 additions
and
109 deletions
+231
-109
api-server/src/main/java/com/zq/api/controller/ApiController.java
+4
-4
common-utils/src/main/java/com/zq/common/config/base/AsyncConfig.java
+26
-8
common-utils/src/main/java/com/zq/common/config/limit/LimitAspect.java
+2
-15
common-utils/src/main/java/com/zq/common/entity/SysLog.java
+87
-0
config-server/src/main/resources/properties/config-dev.yml
+14
-0
config-server/src/main/resources/properties/config-product.yml
+14
-0
config-server/src/main/resources/properties/config-test.yml
+14
-0
sys-server/src/main/java/com/zq/system/config/thread/AsyncTaskExecutePool.java
+70
-70
sys-server/src/main/resources/application.yml
+0
-11
user-server/src/main/java/com/zq/user/service/UserService.java
+0
-1
No files found.
api-server/src/main/java/com/zq/api/controller/ApiController.java
View file @
3699a00a
...
...
@@ -110,13 +110,13 @@ public class ApiController {
// 调试日志
if
(
ApiUtils
.
DEBUG
)
{
System
.
out
.
println
(
"API DEBUG ACTION \n[from="
+
form
+
"]"
//
+
"\n[resp="
+
JSON
.
toJSONString
(
resp
)
+
"]"
//
System
.
out
.
println
(
"API DEBUG ACTION \n[from="
+
form
+
"]"
+
"\n[resp="
+
JSON
.
toJSONString
(
resp
)
+
"]"
+
"\n[time="
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms]"
);
}
String
clientI
P
=
ServletUtil
.
getClientIP
(
request
);
apiService
.
addLog
(
form
,
clientI
P
,
logType
,
resp
.
getMsg
(),
stackTrace
,
System
.
currentTimeMillis
()
-
start
);
String
clientI
p
=
ServletUtil
.
getClientIP
(
request
);
apiService
.
addLog
(
form
,
clientI
p
,
logType
,
resp
.
getMsg
(),
stackTrace
,
System
.
currentTimeMillis
()
-
start
);
return
resp
;
}
...
...
common-utils/src/main/java/com/zq/common/config/base/AsyncConfig.java
View file @
3699a00a
...
...
@@ -7,36 +7,52 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.AsyncConfigurer
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.Executor
;
/**
* 异步执行配置
* <p>
* 注解ConditionalOnProperty(value = "async.pool.enable", havingValue = "true")
* 当获取到async.pool.enable的值等于havingValue的值时才加载配置
*
* @author wilmiam
* @since 2021-07-09 17:50
*/
@Configuration
@ConditionalOnProperty
(
value
=
"async.pool.enable"
,
havingValue
=
"true"
)
@EnableAsync
@ConditionalOnProperty
(
value
=
"task.pool.enable"
,
havingValue
=
"true"
)
public
class
AsyncConfig
implements
AsyncConfigurer
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AsyncConfig
.
class
);
@Value
(
"${async.pool.core-pool-size:5}"
)
/**
* 核心线程池大小
*/
@Value
(
"${task.pool.core-pool-size:5}"
)
private
int
corePoolSize
;
@Value
(
"${async.pool.queue-capacity:10}"
)
/**
* 最大线程数
*/
@Value
(
"${task.pool.max-pool-size:15}"
)
private
int
maxPoolSize
;
@Value
(
"${async.pool.max-pool-size:25}"
)
/**
* 队列容量
*/
@Value
(
"${task.pool.queue-capacity:20}"
)
private
int
queueCapacity
;
@Value
(
"${async.pool.keepalive-seconds:10}"
)
/**
* 活跃时间
*/
@Value
(
"${task.pool.keep-alive-seconds:30}"
)
private
int
threadTimeout
;
@Override
public
Executor
getAsyncExecutor
()
{
log
.
debug
(
">> 初始化spring线程池..."
);
log
.
info
(
">> 初始化spring线程池..."
);
ThreadPoolTaskExecutor
threadPoolTaskExecutor
=
new
ThreadPoolTaskExecutor
();
// 当一个任务通过execute(Runnable)方法欲添加到线程池时:
...
...
@@ -56,6 +72,8 @@ public class AsyncConfig implements AsyncConfigurer {
// 线程池维护线程所允许的空闲时间
threadPoolTaskExecutor
.
setKeepAliveSeconds
(
threadTimeout
);
threadPoolTaskExecutor
.
setThreadNamePrefix
(
"cloud-async-"
);
// don't forget to initialize the thread pool
threadPoolTaskExecutor
.
initialize
();
...
...
common-utils/src/main/java/com/zq/common/config/limit/LimitAspect.java
View file @
3699a00a
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed 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
.
zq
.
common
.
config
.
limit
;
import
com.alibaba.fastjson.JSON
;
...
...
@@ -42,6 +27,8 @@ import java.util.Collections;
import
java.util.List
;
/**
* 限流切面类
*
* @author wilmiam
* @since 2021-07-09 17:51
*/
...
...
common-utils/src/main/java/com/zq/common/entity/SysLog.java
0 → 100644
View file @
3699a00a
package
com
.
zq
.
common
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.Date
;
/**
* 系统日志(SysLog)实体类
*
* @author makejava
* @since 2021-07-12 12:43:07
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName
(
value
=
"sys_log"
)
public
class
SysLog
{
/**
* ID
*/
@ApiModelProperty
(
"ID"
)
private
Long
logId
;
/**
* description
*/
private
String
description
;
/**
* logType
*/
private
String
logType
;
/**
* method
*/
private
String
method
;
/**
* params
*/
private
String
params
;
/**
* requestIp
*/
private
String
requestIp
;
/**
* time
*/
private
Long
time
;
/**
* username
*/
private
String
username
;
/**
* address
*/
private
String
address
;
/**
* browser
*/
private
String
browser
;
/**
* exceptionDetail
*/
private
String
exceptionDetail
;
/**
* createTime
*/
private
Date
createTime
;
}
\ No newline at end of file
config-server/src/main/resources/properties/config-dev.yml
View file @
3699a00a
...
...
@@ -43,5 +43,19 @@ jwt:
# 续期时间范围,默认 1小时,这里单位毫秒
renew
:
3600000
#线程池配置
task
:
pool
:
# 是否启用线程池
enable
:
true
# 核心线程池大小
core-pool-size
:
5
# 最大线程数
max-pool-size
:
15
# 队列容量
queue-capacity
:
20
# 活跃时间
keep-alive-seconds
:
30
#日志等级
logging.level.com.zq.*
:
debug
config-server/src/main/resources/properties/config-product.yml
View file @
3699a00a
...
...
@@ -42,3 +42,17 @@ jwt:
detect
:
1800000
# 续期时间范围,默认 1小时,这里单位毫秒
renew
:
3600000
#线程池配置
task
:
pool
:
# 是否启用线程池
enable
:
true
# 核心线程池大小
core-pool-size
:
5
# 最大线程数
max-pool-size
:
15
# 队列容量
queue-capacity
:
20
# 活跃时间
keep-alive-seconds
:
30
config-server/src/main/resources/properties/config-test.yml
View file @
3699a00a
...
...
@@ -42,3 +42,17 @@ jwt:
detect
:
1800000
# 续期时间范围,默认 1小时,这里单位毫秒
renew
:
3600000
#线程池配置
task
:
pool
:
# 是否启用线程池
enable
:
true
# 核心线程池大小
core-pool-size
:
5
# 最大线程数
max-pool-size
:
15
# 队列容量
queue-capacity
:
20
# 活跃时间
keep-alive-seconds
:
30
sys-server/src/main/java/com/zq/system/config/thread/AsyncTaskExecutePool.java
View file @
3699a00a
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed 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
.
zq
.
system
.
config
.
thread
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.annotation.AsyncConfigurer
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* 异步任务线程池装配类
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
* @date 2019年10月31日15:06:18
*/
@Slf4j
@Configuration
public
class
AsyncTaskExecutePool
implements
AsyncConfigurer
{
/** 注入配置类 */
private
final
AsyncTaskProperties
config
;
public
AsyncTaskExecutePool
(
AsyncTaskProperties
config
)
{
this
.
config
=
config
;
}
@Override
public
Executor
getAsyncExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
//核心线程池大小
executor
.
setCorePoolSize
(
config
.
getCorePoolSize
());
//最大线程数
executor
.
setMaxPoolSize
(
config
.
getMaxPoolSize
());
//队列容量
executor
.
setQueueCapacity
(
config
.
getQueueCapacity
());
//活跃时间
executor
.
setKeepAliveSeconds
(
config
.
getKeepAliveSeconds
());
//线程名字前缀
executor
.
setThreadNamePrefix
(
"el-async-"
);
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
executor
.
initialize
();
return
executor
;
}
@Override
public
AsyncUncaughtExceptionHandler
getAsyncUncaughtExceptionHandler
()
{
return
(
throwable
,
method
,
objects
)
->
{
log
.
error
(
"===="
+
throwable
.
getMessage
()+
"===="
,
throwable
);
log
.
error
(
"exception method:"
+
method
.
getName
());
};
}
}
/
/ /
*
//
* Copyright 2019-2020 Zheng Jie
//
*
//
* Licensed 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.zq.system.config.thread;
//
//
import lombok.extern.slf4j.Slf4j;
//
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
//
import org.springframework.context.annotation.Configuration;
//
import org.springframework.scheduling.annotation.AsyncConfigurer;
//
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//
import java.util.concurrent.Executor;
//
import java.util.concurrent.ThreadPoolExecutor;
//
/
/ /
**
//
* 异步任务线程池装配类
//
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
//
* @date 2019年10月31日15:06:18
//
*/
//
@Slf4j
//
@Configuration
//
public class AsyncTaskExecutePool implements AsyncConfigurer {
//
//
/** 注入配置类 */
//
private final AsyncTaskProperties config;
//
//
public AsyncTaskExecutePool(AsyncTaskProperties config) {
//
this.config = config;
//
}
//
//
@Override
//
public Executor getAsyncExecutor() {
//
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//
//核心线程池大小
//
executor.setCorePoolSize(config.getCorePoolSize());
//
//最大线程数
//
executor.setMaxPoolSize(config.getMaxPoolSize());
//
//队列容量
//
executor.setQueueCapacity(config.getQueueCapacity());
//
//活跃时间
//
executor.setKeepAliveSeconds(config.getKeepAliveSeconds());
//
//线程名字前缀
//
executor.setThreadNamePrefix("el-async-");
//
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
//
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
//
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//
executor.initialize();
//
return executor;
//
}
//
//
@Override
//
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
//
return (throwable, method, objects) -> {
//
log.error("===="+throwable.getMessage()+"====", throwable);
//
log.error("exception method:"+method.getName());
//
};
//
}
//
}
sys-server/src/main/resources/application.yml
View file @
3699a00a
...
...
@@ -65,17 +65,6 @@ spring:
dialect
:
org.hibernate.dialect.MySQL5InnoDBDialect
open-in-view
:
true
task
:
pool
:
# 核心线程池大小
core-pool-size
:
10
# 最大线程数
max-pool-size
:
30
# 活跃时间
keep-alive-seconds
:
60
# 队列容量
queue-capacity
:
50
#七牛云
qiniu
:
# 文件大小 /M
...
...
user-server/src/main/java/com/zq/user/service/UserService.java
View file @
3699a00a
...
...
@@ -46,7 +46,6 @@ public class UserService {
String
code
=
RandomUtil
.
randomNumbers
(
6
);
String
content
=
"您的验证码为:"
+
code
+
"(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。"
;
// TODO 发送验证码
log
.
info
(
">> phone: {}, sendCode: {}, success: "
,
phone
,
code
);
redisUtils
.
setStr
(
UserCacheKeys
.
authCodeKey
(
phone
),
code
,
5
);
}
...
...
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