Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7ab531ac
authored
Jan 16, 2024
by
罗志长
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
async
parent
5fed9d5e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
server-common/src/main/java/com/makeit/config/AsyncConfig.java
server-web/src/main/java/com/makeit/mqtt/MqttPushClient.java
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-common/src/main/java/com/makeit/config/AsyncConfig.java
0 → 100644
View file @
7ab531ac
package
com
.
makeit
.
config
;
import
com.alibaba.ttl.threadpool.TtlExecutors
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ThreadPoolExecutor
;
@Configuration
public
class
AsyncConfig
{
@Bean
(
name
=
"asyncTaskExecutor"
)
public
Executor
asyncTaskExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
executor
.
setCorePoolSize
(
5
);
executor
.
setMaxPoolSize
(
10
);
executor
.
setQueueCapacity
(
500
);
executor
.
setThreadNamePrefix
(
"async-service-"
);
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
CallerRunsPolicy
());
executor
.
setKeepAliveSeconds
(
60
);
executor
.
setAllowCoreThreadTimeOut
(
false
);
executor
.
initialize
();
return
TtlExecutors
.
getTtlExecutor
(
executor
);
}
}
server-web/src/main/java/com/makeit/mqtt/MqttPushClient.java
View file @
7ab531ac
...
...
@@ -54,10 +54,12 @@ public class MqttPushClient {
client
.
setCallback
(
pushCallback
);
client
.
connect
(
options
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"mqtt连接失败"
,
e
);
e
.
printStackTrace
();
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"mqtt连接失败"
,
e
);
e
.
printStackTrace
();
}
}
...
...
server-web/src/main/java/com/makeit/mqtt/PushCallback.java
View file @
7ab531ac
...
...
@@ -104,6 +104,7 @@ public class PushCallback implements MqttCallbackExtended {
}
@Override
@Async
(
"asyncTaskExecutor"
)
public
void
messageArrived
(
String
topic
,
MqttMessage
message
)
{
try
{
// 收到消息并设置返回字符串格式
...
...
@@ -161,10 +162,8 @@ public class PushCallback implements MqttCallbackExtended {
if
(!
"0"
.
equals
(
success
))
{
return
;
}
CompletableFuture
.
runAsync
(()
->
{
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
(),
properties
);
RedisUtil
.
delete
(
redisKey
);
});
// 要加线程池
platDeviceService
.
syncIotProperties
(
device
.
getDeviceId
(),
properties
);
RedisUtil
.
delete
(
redisKey
);
}
}
...
...
@@ -174,7 +173,6 @@ public class PushCallback implements MqttCallbackExtended {
* @param device
*/
@TenantIdIgnore
@Async
public
void
checkAlarm
(
DeviceInfo
device
)
{
HeaderInfo
headers
=
device
.
getHeaders
();
List
<
HeaderInfo
.
Bind
>
bindings
=
headers
.
getBindings
();
...
...
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