You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@artemis.apache.org by "Jayakumarindran Thanakodi (Jira)" <ji...@apache.org> on 2026/10/21 13:22:00 UTC

[jira] [Created] (ARTEMIS-6314) MQTT 5: a retained PUBLISH is not delivered to an established wildcard or shared subscription

Jayakumarindran Thanakodi created ARTEMIS-6314:
--------------------------------------------------

             Summary: MQTT 5: a retained PUBLISH is not delivered to an established wildcard or shared subscription
                 Key: ARTEMIS-6314
                 URL: https://issues.apache.org/jira/browse/ARTEMIS-6314
             Project: Artemis
          Issue Type: Bug
          Components: MQTT
    Affects Versions: 2.57.0
            Reporter: Jayakumarindran Thanakodi


When an MQTT 5 client is subscribed with a topic filter that is not the topic itself (a wildcard filter such as {{base/#}}, or a shared subscription such as {{$share/group/base/a}}), a PUBLISH with the RETAIN flag set that arrives while it is subscribed is never delivered to it. Retained messages sent to that client when it subscribes are not affected, nor are MQTT 3.x clients or subscriptions to the exact topic.

{{MQTTPublishManager.publishToClient}} decides the RETAIN flag of such a message from the subscription's Retain As Published option, and looks the subscription up by the message's topic name:

{code:java}
MqttTopicSubscription sub = session.getState().getSubscriptionItem(topic).getSubscription();
{code}

Subscriptions are keyed by topic filter, so there is no entry for the topic {{base/a}}, {{getSubscriptionItem}} returns null, and the message is not sent:

{noformat}
WARN  [org.apache.activemq.artemis.core.protocol.mqtt] AMQ832000: Unable to send message to MQTT client ...
java.lang.NullPointerException: Cannot invoke "org.apache.activemq.artemis.core.protocol.mqtt.SubscriptionItem.getSubscription()" because the return value of "org.apache.activemq.artemis.core.protocol.mqtt.MQTTSessionState.getSubscriptionItem(String)" is null
	at org.apache.activemq.artemis.core.protocol.mqtt.MQTTPublishManager.publishToClient(MQTTPublishManager.java:445)
{noformat}

This happens whatever the subscription's Retain As Published option is.

Steps to reproduce (MQTT 5, e.g. Paho):
# Client A subscribes to {{base/#}} at QoS 1.
# Client B publishes to {{base/a}} at QoS 1 with RETAIN set.
# A receives nothing, and the broker logs AMQ832000 as above. Subscribing to {{base/a}} instead, or publishing without RETAIN, delivers the message.

The fix is to take the subscription served by the consumer delivering the message rather than looking it up by topic name.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org
For additional commands, e-mail: issues-help@artemis.apache.org