Skip to content

Commit b59b1e7

Browse files
authored
Merge pull request #172 from laurentpeters/issue_171
#171: add a PathMatcher based on the subscription header
2 parents 40bbb34 + 9208f87 commit b59b1e7

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
@@ -318,4 +318,11 @@ public boolean isConnected() {
318318
public void setLegacyWhitespace(boolean legacyWhitespace) {
319319
this.legacyWhitespace = legacyWhitespace;
320320
}
321+
322+
/** returns the to topic (subscription id) corresponding to a given destination
323+
* @param dest the destination
324+
* @return the topic (subscription id) or null if no topic corresponds to the destination */
325+
public String getTopicId(String dest) {
326+
return topics.get(dest);
327+
}
321328
}
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)