OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

mqtt message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]

Subject: [OASIS Issue Tracker] Commented: (MQTT-58) How many messages are received for overlapping subscriptions?

    [ http://tools.oasis-open.org/issues/browse/MQTT-58?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34227#action_34227 ] 

Peter Niblett commented on MQTT-58:

This is a comment both on this issue, and on issue 59 which is very closely related to it. 

The bit about only receiving one copy of the message has always seemed strange to me, however I can see that it makes sense in a protocol that has been designed to be economical in its use of the network.

Al Stockdill-Mander has pointed out to me that you can view each MQTT connection as owning a single subscription object. Each time you subscribe you are adding a new message filter to that object, and each time a message is published the subscription evaluates these filters. If the message matches any of the filters then the message is forwarded to that subscriber. The subscription is in effect the logical OR of all these filters (If an application really wants to have two independent subscriptions, presumably because its handling the messages in independent parts of its logic, then it can always create two separate MQTT connections.

A logical consequence of this is that if a client performs two SUBSCRIBEs with exactly the same Topic and Requested QoS values, then the second one has no effect at all. I suspect this fact is relied upon by many applications that use cleanSession = 0. Such applications might well issue SUBSCRIBEs each time they connect, just in case it's the first time in, or in case someone has deleted the session state held on the server. Ir would be unfortunate they ended up getting one more copy of each message as a result of each reconnection.

Turning to the QoS question

i) In the case where the client sends in two SUBSCRIBES with exactly the same Topic expression but a different QoS, I would expect the later one to win.This allows the application to change its mind about the QoS it wants. In terms of the filter model i discussed earlier, this means that the each filter is associated with a "Requested QoS" value as well as its Topic Expression. The effect of a SUBSCRIBE is to update the Requested QoS of an existing filter (if there already is one) or to add a new filter (if there isn't already one for thie Topic Expression).

ii) Having done that all the filters associated with a client's connection will have distinct topic expressions, but we still have to deal with the case where a published message passes more than one filter, and these filters have different requested QoS values. Ideally it would be the most specific that wins, but to specify that we would have to define an ordering relation on topic expressions that allows us to specify which one of a pair of expressions is the more specific.

This ordering rule could end up being somewhat arbitrary, for example would you rate a/+/c as being more or less specific than a/b/+ ? Do we say that a/b/c/d/e matches a/+/+/+/e more or less precisely than it matches a/b/c/d/# ?

You could take a relatively simple approach and do something like this

1. An Expression with no wild cards is the clear winner
2. Expressions with no # are considered next, and are ranked by the number of +s that they contain (the fewer the better)
3. Expressions with # are considered next and are ranked by the number of non wildcarded levels they contain (the more the better)
4. Where you get a tie then pick the highest QoS (as Al has suggested)

But even this is getting a bit complicated. It might be better just to pick the highest QoS - after eliminating filters with duplicate topic expressions as in i). That would satisfy what I think is the most likely kind of use case (a broad catchall filter with low QoS and one or two more specific ones with higher QoS for more important topics).

> How many messages are received for overlapping subscriptions?
> -------------------------------------------------------------
>                 Key: MQTT-58
>                 URL: http://tools.oasis-open.org/issues/browse/MQTT-58
>             Project: OASIS Message Queuing Telemetry Transport (MQTT) TC
>          Issue Type: Improvement
>          Components: core
>            Reporter: Allan Stockdill-Mander 
> A client has subscribed to a/+ with QoS2 and a/b with QoS1. A message is published to a/b. Does the client receive one or two messages? If one which QoS would apply?

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://tools.oasis-open.org/issues/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]