Skip to content

Conversation

Namoshek
Copy link
Collaborator

This PR introduces a new feature for subscriptions made on a wildcard topic. All matched wildcard parts of the topic are now extracted and passed to the subscription callback. This is best explained with an example:

Subscription made on topic pattern 'foo/bar/+'
Message received for topic 'foo/bar/baz'
The matched wildcard topic levels are passed to the subscription callback: ['baz']

Subscription made on topic pattern 'foo/+/bar/#'
Message received for topic 'foo/baz/bar/hello/world'
The matched wildcard topic levels are passed to the subscription callback: ['baz', 'hello/world']

The matched wildcards are passed as fourth parameter to the subscription callback:

$mqtt->subscribe('foo/+/bar/#', function ($topic, $message, $retained, $matchedWildcards) {
    echo sprintf("Received message on topic [%s]: %s\n", $topic, $message);
}, 0);

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

85.7% 85.7% Coverage
0.0% 0.0% Duplication

@Namoshek Namoshek merged commit af1fc00 into master Oct 30, 2022
@Namoshek Namoshek deleted the feature/topic-wildcards-as-callback-parameter branch October 30, 2022 20:53
@Namoshek Namoshek added the enhancement New feature or request label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant