Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeoFlyApi
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
GeoFly
GeoFlyApi
Commits
17092f18
Commit
17092f18
authored
Mar 06, 2026
by
guoxuejian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enhance subscription logic to support wildcard checks and improve unsubscribe handling
parent
c07b3aed
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
5 deletions
+35
-5
cloud-sdk/src/main/java/com/dji/sdk/mqtt/MqttTopicServiceImpl.java
+35
-5
No files found.
cloud-sdk/src/main/java/com/dji/sdk/mqtt/MqttTopicServiceImpl.java
View file @
17092f18
...
@@ -28,8 +28,8 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
...
@@ -28,8 +28,8 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
public
void
subscribe
(
String
...
topics
)
{
public
void
subscribe
(
String
...
topics
)
{
Set
<
String
>
topicSet
=
new
HashSet
<>(
Arrays
.
asList
(
getSubscribedTopic
()));
Set
<
String
>
topicSet
=
new
HashSet
<>(
Arrays
.
asList
(
getSubscribedTopic
()));
for
(
String
topic
:
topics
)
{
for
(
String
topic
:
topics
)
{
if
(
topicSet
.
contains
(
topic
))
{
if
(
topicSet
.
contains
(
topic
)
||
isCoveredByWildcard
(
topicSet
,
topic
)
)
{
return
;
continue
;
}
}
subscribe
(
topic
,
1
);
subscribe
(
topic
,
1
);
}
}
...
@@ -38,7 +38,7 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
...
@@ -38,7 +38,7 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
@Override
@Override
public
void
subscribe
(
String
topic
,
int
qos
)
{
public
void
subscribe
(
String
topic
,
int
qos
)
{
Set
<
String
>
topicSet
=
new
HashSet
<>(
Arrays
.
asList
(
getSubscribedTopic
()));
Set
<
String
>
topicSet
=
new
HashSet
<>(
Arrays
.
asList
(
getSubscribedTopic
()));
if
(
topicSet
.
contains
(
topic
))
{
if
(
topicSet
.
contains
(
topic
)
||
isCoveredByWildcard
(
topicSet
,
topic
)
)
{
return
;
return
;
}
}
log
.
debug
(
"subscribe topic: {}"
,
topic
);
log
.
debug
(
"subscribe topic: {}"
,
topic
);
...
@@ -47,11 +47,41 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
...
@@ -47,11 +47,41 @@ public class MqttTopicServiceImpl implements IMqttTopicService {
@Override
@Override
public
void
unsubscribe
(
String
...
topics
)
{
public
void
unsubscribe
(
String
...
topics
)
{
log
.
debug
(
"unsubscribe topic: {}"
,
Arrays
.
toString
(
topics
));
Set
<
String
>
currentTopics
=
new
HashSet
<>(
Arrays
.
asList
(
getSubscribedTopic
()));
adapter
.
removeTopic
(
topics
);
for
(
String
topic
:
topics
)
{
if
(!
currentTopics
.
contains
(
topic
))
{
continue
;
}
if
(
isCoveredByWildcard
(
currentTopics
,
topic
))
{
log
.
debug
(
"skip unsubscribe, topic {} is covered by wildcard"
,
topic
);
continue
;
}
log
.
debug
(
"unsubscribe topic: {}"
,
topic
);
adapter
.
removeTopic
(
topic
);
}
}
}
public
String
[]
getSubscribedTopic
()
{
public
String
[]
getSubscribedTopic
()
{
return
adapter
.
getTopic
();
return
adapter
.
getTopic
();
}
}
/**
* Check if a specific topic is already covered by a single-level wildcard (+) subscription.
* e.g. "thing/product/DRONE-001/osd" is covered by "thing/product/+/osd"
*/
private
boolean
isCoveredByWildcard
(
Set
<
String
>
existingTopics
,
String
topic
)
{
String
[]
parts
=
topic
.
split
(
"/"
);
if
(
parts
.
length
<
3
)
{
return
false
;
}
for
(
int
i
=
0
;
i
<
parts
.
length
;
i
++)
{
String
[]
wildcardParts
=
parts
.
clone
();
wildcardParts
[
i
]
=
"+"
;
String
wildcardTopic
=
String
.
join
(
"/"
,
wildcardParts
);
if
(
existingTopics
.
contains
(
wildcardTopic
))
{
return
true
;
}
}
return
false
;
}
}
}
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