You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@artemis.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2026/10/21 13:23:00 UTC
[jira] [Work logged] (ARTEMIS-6314) MQTT 5: a retained PUBLISH is not delivered to an established wildcard or shared subscription
[ https://issues.apache.org/jira/browse/ARTEMIS-6314?focusedWorklogId=1048781&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1048781 ]
ASF GitHub Bot logged work on ARTEMIS-6314:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 21/Oct/26 13:22
Start Date: 21/Oct/26 13:22
Worklog Time Spent: 10m
Work Description: grepjava opened a new pull request, #6816:
URL: https://github.com/apache/artemis/pull/6816
`MQTTPublishManager.publishToClient` looked up the subscription of an MQTT 5 client by the message's topic name to read its Retain As Published option. Subscriptions are keyed by topic filter, so for a wildcard (`base/#`) or shared (`$share/group/base/a`) subscription the lookup returned null, the resulting `NullPointerException` was logged as AMQ832000, and a retained PUBLISH sent while the client was subscribed was never delivered.
It now takes the subscription served by the consumer delivering the message (`MQTTSessionState.getSubscriptionItemForConsumer`), so the option is read from the subscription that matched.
Adds tests to `PublishTests` for a wildcard subscription with Retain As Published 1 and 0, and for a shared subscription.
This is separate from the retained-message work in #6734 and #6778, which does not touch this lookup.
https://issues.apache.org/jira/browse/ARTEMIS-6314
Issue Time Tracking
-------------------
Worklog Id: (was: 1048781)
Remaining Estimate: 0h
Time Spent: 10m
> 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
> Priority: Major
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> 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