Skip to content

Commit 9208f87

Browse files
committed
#171: add a PathMatcher based on the subscription header
1 parent e71248f commit 9208f87

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/src/main/java/ua/naiksoftware/stomp/StompClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,11 @@ public boolean isConnected() {
316316
public void setLegacyWhitespace(boolean legacyWhitespace) {
317317
this.legacyWhitespace = legacyWhitespace;
318318
}
319+
320+
/** returns the to topic (subscription id) corresponding to a given destination
321+
* @param dest the destination
322+
* @return the topic (subscription id) or null if no topic corresponds to the destination */
323+
public String getTopicId(String dest) {
324+
return topics.get(dest);
325+
}
319326
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ua.naiksoftware.stomp.pathmatcher;
2+
3+
import ua.naiksoftware.stomp.dto.StompHeader;
4+
import ua.naiksoftware.stomp.dto.StompMessage;
5+
6+
public class SubscriptionPathMatcher implements PathMatcher {
7+
8+
@Override
9+
public boolean matches(String path, StompMessage msg) {
10+
// Compare subscription
11+
String pathSubscription = stompClient.getTopicId(path);
12+
if (pathSubscription == null) return false;
13+
String subscription = msg.findHeader(StompHeader.SUBSCRIPTION);
14+
return pathSubscription.equals(subscription);
15+
}
16+
}

0 commit comments

Comments
 (0)