Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-smart-message-channel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 16e7bf12
authored
May 17, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码规范
1 parent
64391613
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
src/main/java/cn/com/glsx/consumer/config/TuyaConfig.java
src/main/java/cn/com/glsx/consumer/modules/consumers/TuyaComsumer.java
src/main/java/cn/com/glsx/consumer/config/TuyaConfig.java
0 → 100644
View file @
16e7bf1
package
cn
.
com
.
glsx
.
consumer
.
config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author zhouhaibao
* @date 2021/5/17 13:54
*/
@Configuration
@Data
public
class
TuyaConfig
{
@Value
(
"${pulsar.serviceUrl}"
)
private
String
serviceUrl
;
@Value
(
"${pulsar.accessId}"
)
private
String
accessId
;
@Value
(
"${pulsar.accessKey}"
)
private
String
accessKey
;
@Value
(
"${pulsar.maxRedeliverCount}"
)
private
int
maxRedeliverCount
;
@Value
(
"${pulsar.topic}"
)
private
String
topic
;
@Value
(
"${pulsar.subscriptionName}"
)
private
String
subscriptionName
;
}
src/main/java/cn/com/glsx/consumer/modules/consumers/TuyaComsumer.java
View file @
16e7bf1
package
cn
.
com
.
glsx
.
consumer
.
modules
.
consumers
;
package
cn
.
com
.
glsx
.
consumer
.
modules
.
consumers
;
import
cn.com.glsx.consumer.config.TuyaConfig
;
import
cn.com.glsx.consumer.modules.consumers.pulsar.MqConsumer
;
import
cn.com.glsx.consumer.modules.consumers.pulsar.MqConsumer
;
import
cn.com.glsx.consumer.modules.utils.AESBase64Utils
;
import
cn.com.glsx.consumer.modules.utils.AESBase64Utils
;
import
cn.com.glsx.consumer.common.constant.Contants
;
import
cn.com.glsx.consumer.common.constant.Contants
;
...
@@ -8,7 +9,7 @@ import cn.com.glsx.consumer.modules.model.response.device.MessageRep;
...
@@ -8,7 +9,7 @@ import cn.com.glsx.consumer.modules.model.response.device.MessageRep;
import
cn.com.glsx.consumer.modules.service.InfoService
;
import
cn.com.glsx.consumer.modules.service.InfoService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.
Value
;
import
org.springframework.beans.factory.annotation.
Autowired
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -21,28 +22,13 @@ public class TuyaComsumer implements CommandLineRunner {
...
@@ -21,28 +22,13 @@ public class TuyaComsumer implements CommandLineRunner {
@Resource
@Resource
private
InfoService
infoService
;
private
InfoService
infoService
;
@Value
(
"${pulsar.serviceUrl}"
)
@Autowired
private
String
serviceUrl
;
private
TuyaConfig
tuyaConfig
;
@Value
(
"${pulsar.accessId}"
)
private
String
accessId
;
@Value
(
"${pulsar.accessKey}"
)
private
String
accessKey
;
@Value
(
"${pulsar.maxRedeliverCount}"
)
private
int
maxRedeliverCount
;
@Value
(
"${pulsar.topic}"
)
private
String
topic
;
@Value
(
"${pulsar.subscriptionName}"
)
private
String
subscriptionName
;
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
MqConsumer
mqConsumer
=
MqConsumer
.
build
().
serviceUrl
(
serviceUrl
).
accessId
(
accessId
).
accessKey
(
accessKey
).
topic
(
topic
).
subscriptionName
(
subscriptionName
)
MqConsumer
mqConsumer
=
MqConsumer
.
build
().
serviceUrl
(
tuyaConfig
.
getServiceUrl
()).
accessId
(
tuyaConfig
.
getAccessId
()).
accessKey
(
tuyaConfig
.
getAccessKey
()).
topic
(
tuyaConfig
.
getTopic
()).
subscriptionName
(
tuyaConfig
.
getSubscriptionName
()
)
.
maxRedeliverCount
(
maxRedeliverCount
).
messageListener
(
.
maxRedeliverCount
(
tuyaConfig
.
getMaxRedeliverCount
()
).
messageListener
(
message
->
{
message
->
{
log
.
info
(
"Message received:"
+
new
String
(
message
.
getData
())
+
",seq="
log
.
info
(
"Message received:"
+
new
String
(
message
.
getData
())
+
",seq="
+
message
.
getSequenceId
()
+
",time="
+
message
.
getPublishTime
()
+
",consumed time="
+
message
.
getSequenceId
()
+
",time="
+
message
.
getPublishTime
()
+
",consumed time="
...
@@ -50,12 +36,12 @@ public class TuyaComsumer implements CommandLineRunner {
...
@@ -50,12 +36,12 @@ public class TuyaComsumer implements CommandLineRunner {
String
jsonMessage
=
new
String
(
message
.
getData
());
String
jsonMessage
=
new
String
(
message
.
getData
());
MessageRep
vo
=
JSON
.
parseObject
(
jsonMessage
,
MessageRep
.
class
);
MessageRep
vo
=
JSON
.
parseObject
(
jsonMessage
,
MessageRep
.
class
);
Integer
protocol
=
vo
.
getProtocol
();
Integer
protocol
=
vo
.
getProtocol
();
if
(
protocol
.
equals
(
Contants
.
STATUS_APPEAR
))
{
if
(
protocol
.
equals
(
Contants
.
STATUS_APPEAR
))
{
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
accessKey
.
substring
(
8
,
24
));
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
tuyaConfig
.
getAccessKey
()
.
substring
(
8
,
24
));
log
.
info
(
"the real message data:"
+
data
);
log
.
info
(
"the real message data:"
+
data
);
infoService
.
processMessage
(
data
);
infoService
.
processMessage
(
data
);
}
else
if
(
protocol
.
equals
(
Contants
.
event_APPEAR
))
{
}
else
if
(
protocol
.
equals
(
Contants
.
event_APPEAR
))
{
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
accessKey
.
substring
(
8
,
24
));
String
data
=
AESBase64Utils
.
decrypt
(
vo
.
getData
(),
tuyaConfig
.
getAccessKey
()
.
substring
(
8
,
24
));
log
.
info
(
"the real message data:"
+
data
);
log
.
info
(
"the real message data:"
+
data
);
infoService
.
processEeventMessage
(
data
);
infoService
.
processEeventMessage
(
data
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment