Expected subscription/topic behaviour

212 views
Skip to first unread message

Roger Light

unread,
Dec 8, 2011, 10:43:55 AM12/8/11
to mq...@googlegroups.com
Hi,

I've just had a bug reported against mosquitto (
https://bugs.launchpad.net/mosquitto/+bug/901697 ) where when a
subscription to something/# exists and a message is published to
something/ then mosquitto crashes. Obviously crashing is the incorrect
behaviour, but aside from that I'm not sure how to treat that topic. I
think my options are:

* Treat topics ending in / as invalid and silently swallow
subscriptions and messages that use them
* Treat topics ending in / as not ending in / - ie removing the final slash.
* Treat topics ending in / as having a zero length final level of
hierarchy, so a message published to something/ would go to
subscriptions at something/ something/# something/+ but not something

Any suggestions?

My own choice would be to define topics ending in / as invalid in the spec.

Cheers,

Roger

Nicholas O'Leary

unread,
Dec 8, 2011, 11:15:08 AM12/8/11
to mq...@googlegroups.com
Having reminded myself of the how the various cases in this area are
handled, here is a summary of the behaviour:
- a topic ending in a slash is considered equivalent to the same
topic without the slash, which enables the wildcards to behave like
this:
- a subscription to A/# is a subscription to the topic A and all
topics beneath A
- a subscription to A/+ is a subscription to the topics directly
beneath, but not A itself
- a subscription to A/+/# is a subscription to all topics beneath A,
but not A itself

While the difference between A/# and A/+ may appear inconsistent, it
is consistent with how the two wildcard characters are defined:
# matches zero or more levels
+ matches exactly one level

Ultimately, topics are arbitrary strings upon which we have said the
'/' has an additional meaning. There is currently no such thing as an
invalid topic (assuming it is valid UTF etc) (even an empty string is
a valid topic - although whether that should be the case is a separate
discussion) (of course it shouldn't contain wildcards unless it is in
the context of a subscription) (any more caveats?) (nope).

MQTT v3 only has positive acknowledgements, it would not be possible
to inform a client it had sent an invalid topic - so as you say we
would have to silently swallow them or kick the client off.

Removing the A/==A equivalence would mean you wouldn't be able to
subscribe to A and all of its sub-topics in a single subscription
request (A/# as above).

Cheers,
Nick

> --
> To learn more about MQTT please visit http://mqtt.org
>
> To post to this group, send email to mq...@googlegroups.com
> To unsubscribe from this group, send email to
> mqtt+uns...@googlegroups.com
>
> For more options, visit this group at
> http://groups.google.com/group/mqtt

Roger Light

unread,
Dec 8, 2011, 11:54:23 AM12/8/11
to mq...@googlegroups.com
On Thu, Dec 8, 2011 at 4:15 PM, Nicholas O'Leary <nick....@gmail.com> wrote:

>  - a topic ending in a slash is considered equivalent to the same
> topic without the slash, which enables the wildcards to behave like
> this:

This is a subtly different description to the one in the spec. If you
know the above, the spec makes more sense but without it there's room
for confusion (obviously - I got it wrong). The way I read the spec up
til now was that A/# matching A was more a feature of the # wildcard
than the way the hierarchy separator works. It makes more sense now,
thanks.

Cheers,

Roger

andyp...@gmail.com

unread,
Dec 9, 2011, 10:14:21 AM12/9/11
to mq...@googlegroups.com
Worth getting this into the wiki on mqtt.org for future reference
maybe? Doesn't mean it wouldn't be open to future discussion or
modification as the spec goes to standards, but at least we can have
it written down somewhere :-)

> --
> To learn more about MQTT please visit http://mqtt.org
>
> To post to this group, send email to mq...@googlegroups.com
> To unsubscribe from this group, send email to
> mqtt+uns...@googlegroups.com
>
> For more options, visit this group at
> http://groups.google.com/group/mqtt

--
Andy Piper | Farnborough, Hampshire (UK)
blog: http://andypiper.co.uk   |   skype: andypiperuk
twitter: @andypiper  |  images: http://www.flickr.com/photos/andypiper

Sy

unread,
Dec 9, 2011, 10:42:53 AM12/9/11
to MQ Telemetry Transport
The way '/' is treated works the same way that file systems tread '/'
where by its optional if nothing follows it and ignored.

Could we expand the handling of topics to include regular expressions?

Or '?' to allow omission of single characters?


On Dec 9, 3:14 pm, "andypipe...@gmail.com" <andypipe...@gmail.com>
wrote:


> Worth getting this into the wiki on mqtt.org for future reference
> maybe? Doesn't mean it wouldn't be open to future discussion or
> modification as the spec goes to standards, but at least we can have
> it written down somewhere :-)
>
>
>
>
>
>
>
>
>
> On Thu, Dec 8, 2011 at 16:54, Roger Light <ro...@atchoo.org> wrote:

> > On Thu, Dec 8, 2011 at 4:15 PM, Nicholas O'Leary <nick.ole...@gmail.com> wrote:
>
> >>  - a topic ending in a slash is considered equivalent to the same
> >> topic without the slash, which enables the wildcards to behave like
> >> this:
>
> > This is a subtly different description to the one in the spec. If you
> > know the above, the spec makes more sense but without it there's room
> > for confusion (obviously - I got it wrong). The way I read the spec up
> > til now was that A/# matching A was more a feature of the # wildcard
> > than the way the hierarchy separator works. It makes more sense now,
> > thanks.
>
> > Cheers,
>
> > Roger
>
> > --

> > To learn more about MQTT please visithttp://mqtt.org

Reply all
Reply to author
Forward
0 new messages