Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multilevel wildcard does not match empty subtree #56

Closed
pinchpe opened this issue Sep 23, 2019 · 2 comments
Closed

multilevel wildcard does not match empty subtree #56

pinchpe opened this issue Sep 23, 2019 · 2 comments

Comments

@pinchpe
Copy link

pinchpe commented Sep 23, 2019

The multi-level wildcard # is not matching an empty subtree. In other words:
A subscription to
/zoo/animal/#

should match

/zoo/animal/zebra
/zoo/animal/elephant
/zoo/animal/bengal/tiger

and it should also match
/zoo/animal
fhmq is not currently handling this case correctly, ie, is not matching /zoo/animal

The following test, which you can run in broker/lib/topics illustrates. (The file is a .go, changed to .txt so could attach)
memtopics_test.txt

@pinchpe
Copy link
Author

pinchpe commented Sep 24, 2019

The fix is very simple but looks like I don't have permissions to push and submit a PR. Here's the patch:

topics $ git diff 53a79caad9f0c09ebc4ce5953bb1c480f6ece5a0 memtopics.go 
diff --git a/broker/lib/topics/memtopics.go b/broker/lib/topics/memtopics.go
index eb81345..012cf3c 100644
--- a/broker/lib/topics/memtopics.go
+++ b/broker/lib/topics/memtopics.go
@@ -244,6 +244,13 @@ func (this *snode) smatch(topic []byte, qos byte, subs *[]interface{}, qoss *[]b
        // let's find the subscribers that match the qos and append them to the list.
        if len(topic) == 0 {
                this.matchQos(qos, subs, qoss)
+
+               // Also need to consider subscribers to the multi-level wildcard since there can be subscribers _both_ to /foo/bar and /foo/bar/#
+               // Note that if a subscriber is subscribed to _both_ topics it is returned twice as it matches both topics.
+               if mwcn, _ := this.snodes[MWC]; mwcn != nil {
+                       mwcn.matchQos(qos, subs, qoss)
+               }
+
                return nil
        }
 

Updated tests: (a .go file which I changed to .txt so could attach)

memtopics_test.txt

@chowyu08
Copy link
Contributor

yes, thanks very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants