YYYYWD commented on code in PR #131:
URL: https://github.com/apache/rocketmq-mqtt/pull/131#discussion_r990636596


##########
mqtt-cs/src/main/java/org/apache/rocketmq/mqtt/cs/protocol/mqtt/handler/MqttSubscribeHandler.java:
##########
@@ -128,4 +159,63 @@ private MqttSubAckMessage getResponse(MqttSubscribeMessage 
mqttSubscribeMessage)
         return mqttSubAckMessage;
     }
 
+
+    private void sendRetainMessage(ChannelHandlerContext ctx, 
Set<Subscription> subscriptions) throws InterruptedException, 
RemotingException, org.apache.rocketmq.remoting.exception.RemotingException {
+
+        String clientId = ChannelInfo.getClientId(ctx.channel());
+        Session session = 
sessionLoop.getSession(ChannelInfo.getId(ctx.channel()));
+        Set<Subscription> preciseTopics = new HashSet<>();
+        Set<Subscription> wildcardTopics = new HashSet<>();
+
+        for (Subscription subscription : subscriptions) {
+            if (!TopicUtils.isWildCard(subscription.getTopicFilter())) {
+                preciseTopics.add(subscription);
+            } else {
+                wildcardTopics.add(subscription);
+            }
+        }
+
+        for (Subscription subscription : preciseTopics) {
+            CompletableFuture<Message> retainedMessage = 
retainedPersistManager.getRetainedMessage(subscription.getTopicFilter());
+            retainedMessage.whenComplete((msg, throwable) -> {
+                if (msg == null) {
+                    return;
+                }
+                _sendMessage(session, clientId, subscription, msg);
+            });
+        }
+
+        for (Subscription subscription : wildcardTopics) {
+
+            CompletableFuture<ArrayList<Message>> future = 
retainedPersistManager.getMsgsFromTrie(subscription);
+            future.whenComplete((msgsList, throwable) -> {
+                for (Message msg : msgsList) {
+                    if (msg == null) {
+                        return;
+                    }
+                    _sendMessage(session, clientId, subscription, msg);
+                }
+            });
+
+        }
+    }
+
+    private void _sendMessage(Session session, String clientId, Subscription 
subscription, Message message) {

Review Comment:
   Fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to