Search code examples
mqtt

MQTT wildcard overlap topic filter causes the client to receive twice


When subscribing to a wildcard and a topic that overlaps that wildcard, the client receives twice the messages because of this overlapping behavior.

Example:

Client-A:
subscribe{aaa/bbb/+/ddd, aaa/bbb/ccc/ddd}

Then, if I publish something on the wildcard topic, Client-A will receive only one:

Client-B:
Publish{aaa/bbb/www/ddd, "blablabla"}

Client-A:
Received{aaa/bbb/www/ddd, "blablabla"}

But, if I publish on the specific topic, Client-A receives twice:

Client-B:
Publish{aaa/bbb/ccc/ddd, "blablabla"}

Client-A:
Received{aaa/bbb/ccc/ddd, "blablabla"}
Received{aaa/bbb/ccc/ddd, "blablabla"}

Checking the MQTT specification, it states this (source, page 36, section 3.3.5 Actions):

When Clients make subscriptions with Topic Filters that include wildcards, it is possible for a Client’s subscriptions to overlap so that a published message might match multiple filters. In this case the Server MUST deliver the message to the Client respecting the maximum QoS of all the matching subscriptions [MQTT-3.3.5-1]. In addition, the Server MAY deliver further copies of the message, one for each additional matching subscription and respecting the subscription’s QoS in each case.

If I use the Paho MQTT-SN Gateway (Server), then the server sends only once. But if I use the Eclipse Public Server, then I receive twice. The behavior is not consistent, or, at least, I cannot expect which behavior will be until I test it.

The question is: is it possible to set the specific behavior for the wildcard overlap to send only once? Or it depends on server-to-server implementation?


Solution

  • As the specification says that either behaviour is correct it becomes a choice for the broker implementers and likewise adding a configuration option to change the behaviour one way or the other would be a choice.

    You will have to test any broker you are using and then consult their documentation to see if it is possible to change the behaviour.

    There is no generic answer to this question.