Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
6eb6fb00
提交
6eb6fb00
authored
9月 15, 2021
作者:
yangli
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
3d443f82
a31790c1
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
78 行增加
和
0 行删除
+78
-0
DefaultHttpService.java
...om/priusis/client/extensions/http/DefaultHttpService.java
+40
-0
HttpController.java
...va/com/priusis/client/extensions/http/HttpController.java
+5
-0
HttpService.java
.../java/com/priusis/client/extensions/http/HttpService.java
+2
-0
DefaultTenantManagerService.java
...m/priusis/client/service/DefaultTenantManagerService.java
+5
-0
TenantManagerService.java
...java/com/priusis/client/service/TenantManagerService.java
+2
-0
MqttService.java
...ain/java/com/priusis/client/service/core/MqttService.java
+7
-0
MqttServiceImpl.java
...java/com/priusis/client/service/core/MqttServiceImpl.java
+17
-0
没有找到文件。
apq-pc-client/src/main/java/com/priusis/client/extensions/http/DefaultHttpService.java
浏览文件 @
6eb6fb00
package
com
.
priusis
.
client
.
extensions
.
http
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.priusis.client.data.kv.KvEntry
;
import
com.priusis.client.extensions.ExtensionUpdate
;
import
com.priusis.client.extensions.http.conf.HttpConfiguration
;
...
...
@@ -69,6 +70,19 @@ public class DefaultHttpService extends ExtensionUpdate implements HttpService {
}
}
@Override
public
void
processEventRequest
(
String
token
,
String
body
)
throws
Exception
{
log
.
trace
(
"[{}] Processing request body [{}] for token [{}]"
,
mqttService
.
getTenantLabel
(),
body
,
token
);
if
(
configuration
!=
null
)
{
if
(
StringUtils
.
isEmpty
(
configuration
.
getToken
())
||
configuration
.
getToken
().
equals
(
token
))
{
processEventBody
(
body
);
}
else
{
log
.
error
(
"[{}] Request token [{}] doesn't match configuration token!"
,
mqttService
.
getTenantLabel
(),
token
);
throw
new
SecurityException
(
"Request token ["
+
token
+
"] doesn't match configuration token!"
);
}
}
}
@Override
public
File
flushRpcDataToFile
(
MqttRpcDataMessage
mqttRpcDataMessage
)
throws
IOException
{
return
mqttService
.
flushRpcDataToFile
(
mqttRpcDataMessage
);
...
...
@@ -79,6 +93,32 @@ public class DefaultHttpService extends ExtensionUpdate implements HttpService {
return
mqttService
.
readFromFile
(
method
);
}
private
void
processEventBody
(
String
body
)
throws
Exception
{
/*JsonNode jsonObject = fromString(body);
String methodName = jsonObject.get("methodName").asText();
int requestId = jsonObject.get("requestId").asInt();
String paramsStr = null;
JsonNode params = jsonObject.get("params");
if (null != params) {
paramsStr = params.toString();
}*/
List
<
KvEntry
>
attrData
=
getKvEntries
(
fromString
(
body
));
DeviceData
dd
=
new
DeviceData
(
attrData
);
if
(
dd
!=
null
)
{
List
<
MqttDeliveryFuture
>
futures
=
new
ArrayList
<>();
if
(!
dd
.
getAttributes
().
isEmpty
())
{
futures
.
add
(
mqttService
.
onDeviceEventUpdate
(
dd
.
getAttributes
()));
}
for
(
Future
future
:
futures
)
{
waitWithTimeout
(
future
);
}
}
else
{
log
.
error
(
"[{}] DeviceData is null. Body [{}] was not parsed successfully!"
,
mqttService
.
getTenantLabel
(),
body
);
throw
new
IllegalArgumentException
(
"Device Data is null. Body ["
+
body
+
"] was not parsed successfully!"
);
}
}
private
void
processBody
(
String
body
)
throws
Exception
{
List
<
KvEntry
>
attrData
=
getKvEntries
(
fromString
(
body
));
DeviceData
dd
=
new
DeviceData
(
attrData
);
...
...
apq-pc-client/src/main/java/com/priusis/client/extensions/http/HttpController.java
浏览文件 @
6eb6fb00
...
...
@@ -30,6 +30,11 @@ public class HttpController {
service
.
processRequest
(
token
,
body
);
}
@RequestMapping
(
value
=
"/uplink_event/{token}"
,
method
=
RequestMethod
.
POST
)
public
void
handleEventRequest
(
@PathVariable
String
token
,
@RequestBody
String
body
)
throws
Exception
{
service
.
processEventRequest
(
token
,
body
);
}
@RequestMapping
(
value
=
"/rpc_cmd/{method}"
,
method
=
RequestMethod
.
GET
)
public
MqttRpcDataMessage
getRpcCmdDataRequest
(
@PathVariable
String
method
)
throws
Exception
{
MqttRpcDataMessage
mqttRpcDataMessage
=
service
.
readFromFile
(
method
);
...
...
apq-pc-client/src/main/java/com/priusis/client/extensions/http/HttpService.java
浏览文件 @
6eb6fb00
...
...
@@ -10,6 +10,8 @@ public interface HttpService extends ExtensionService {
void
processRequest
(
String
token
,
String
body
)
throws
Exception
;
void
processEventRequest
(
String
token
,
String
body
)
throws
Exception
;
File
flushRpcDataToFile
(
MqttRpcDataMessage
mqttRpcDataMessage
)
throws
IOException
;
MqttRpcDataMessage
readFromFile
(
String
method
)
throws
IOException
;
...
...
apq-pc-client/src/main/java/com/priusis/client/service/DefaultTenantManagerService.java
浏览文件 @
6eb6fb00
...
...
@@ -67,6 +67,11 @@ public abstract class DefaultTenantManagerService implements TenantManagerServic
httpService
.
processRequest
(
token
,
body
);
}
@Override
public
void
processEventRequest
(
String
token
,
String
body
)
throws
Exception
{
httpService
.
processEventRequest
(
token
,
body
);
}
@Override
public
File
flushRpcDataToFile
(
MqttRpcDataMessage
mqttRpcDataMessage
)
throws
IOException
{
return
httpService
.
flushRpcDataToFile
(
mqttRpcDataMessage
);
...
...
apq-pc-client/src/main/java/com/priusis/client/service/TenantManagerService.java
浏览文件 @
6eb6fb00
...
...
@@ -10,6 +10,8 @@ public interface TenantManagerService {
void
processRequest
(
String
token
,
String
body
)
throws
Exception
;
void
processEventRequest
(
String
token
,
String
body
)
throws
Exception
;
File
flushRpcDataToFile
(
MqttRpcDataMessage
mqttRpcDataMessage
)
throws
IOException
;
MqttRpcDataMessage
readFromFile
(
String
method
)
throws
IOException
;
...
...
apq-pc-client/src/main/java/com/priusis/client/service/core/MqttService.java
浏览文件 @
6eb6fb00
...
...
@@ -32,6 +32,13 @@ public interface MqttService {
*/
MqttDeliveryFuture
onDeviceAttributesUpdate
(
List
<
KvEntry
>
attributes
);
/**
* Report device event change to Priusisiot
*
* @param attributes - the attribute values list
*/
MqttDeliveryFuture
onDeviceEventUpdate
(
List
<
KvEntry
>
attributes
);
/**
* Report attributes request to Priusisiot
*
...
...
apq-pc-client/src/main/java/com/priusis/client/service/core/MqttServiceImpl.java
浏览文件 @
6eb6fb00
...
...
@@ -57,6 +57,7 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
private
static
final
String
DEVICE_TELEMETRY_TOPIC
=
"devices/telemetry"
;
private
static
final
String
DEVICE_ATTRIBUTES_TOPIC
=
"devices/attrs"
;
private
static
final
String
DEVICE_RPC_TOPIC
=
"devices/rpc"
;
private
static
final
String
DEVICE_EVENT_TOPIC
=
"devices/event"
;
private
static
final
String
DEVICE_GET_ATTRIBUTES_REQUEST_TOPIC
=
"devices/attrs/req/1"
;
private
static
final
String
DEVICE_GET_ATTRIBUTES_RESPONSE_PLUS_TOPIC
=
"devices/attrs/res/+"
;
private
static
final
String
DEVICE_GET_ATTRIBUTES_RESPONSE_TOPIC
=
"devices/attrs/res/1"
;
...
...
@@ -157,6 +158,22 @@ public class MqttServiceImpl implements MqttService, MqttHandler, MqttClientCall
error
->
log
.
warn
(
"[{}] Failed to report device attributes!"
,
msgId
,
error
));
}
@Override
public
MqttDeliveryFuture
onDeviceEventUpdate
(
List
<
KvEntry
>
attributes
)
{
final
int
msgId
=
msgIdSeq
.
incrementAndGet
();
log
.
trace
(
"[{}] Updating device event: {}"
,
msgId
,
attributes
);
ObjectNode
node
=
newNode
();
//ObjectNode deviceNode = node.putObject(deviceName);
attributes
.
forEach
(
kv
->
putToNode
(
node
,
kv
));
final
int
packSize
=
attributes
.
size
();
return
persistMessage
(
DEVICE_EVENT_TOPIC
,
msgId
,
toNodeBytes
(
node
),
message
->
{
log
.
debug
(
"[{}] Device event were delivered!"
,
msgId
);
attributesCount
.
addAndGet
(
packSize
);
},
error
->
log
.
warn
(
"[{}] Failed to report device event!"
,
msgId
,
error
));
}
private
MqttDeliveryFuture
persistMessage
(
String
topic
,
int
msgId
,
byte
[]
payload
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论