Skip to content

fix(binding-mqtt-kafka): advertise maximum qos when qos 2 publish is disabled - #3136

Merged
jfallows merged 7 commits into
fix/3129-mqtt-per-connection-limitsfrom
fix/3130-mqtt-kafka-connack-maximum-qos
Nov 12, 2026
Merged

jfallows merged 7 commits into
fix/3129-mqtt-per-connection-limitsfrom
fix/3130-mqtt-kafka-connack-maximum-qos

Conversation

@jfallows

@jfallows jfallows commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

The MQTT server built the CONNACK Maximum QoS property from subscribeQosMax only. mqtt-kafka always reports subscribeQosMax as 2, so the property was never sent even when QoS 2 PUBLISH is disabled by zilla.binding.mqtt.kafka.publish.qos.max, options.publish.qosMax, or a route whose with.messages uses ${params}. A QoS 2 PUBLISH was then rejected with 0x9B although the client was never told the limit.

MQTT 5.0 [MQTT-3.2.2-9]: a Server that does not support QoS 1 or QoS 2 PUBLISH packets MUST send Maximum QoS in the CONNACK with the highest QoS it supports. The property limits what the client may PUBLISH; subscription QoS is downgraded in the SUBACK, so it is not part of this value.

Changes:

  • MqttServerFactory: the CONNACK Maximum QoS is the per-connection publishQosMax (from the session BEGIN extension), omitted when 2. The Will QoS is rejected with 0x9B (QoS not supported) both at CONNECT, against the configured maximum, and again when the application's session reply arrives, against the reply's publishQosMax, ending the session cleanly so no Will is delivered. The now-unused subscribeQosMax field is removed. MQTT 3.1.1 behavior is unchanged.
  • MqttClientFactory: the Maximum QoS in the remote CONNACK limits the client's own PUBLISH, so it is reported to the application as publishQosMax; subscribeQosMax is no longer derived from it and is the constant 2.
  • mqtt:matchBeginEx (session) now enforces publishQosMax when a script specifies it. It was silently ignored before, so scripts asserting it were vacuous.

Fixes #3130

Stack

PR Branch Base
#3135 (issue #3129) fix/3129-mqtt-per-connection-limits develop
this PR (issue #3130) fix/3130-mqtt-kafka-connack-maximum-qos fix/3129-mqtt-per-connection-limits
issue #3131 fix/3131-mqtt-kafka-message-expiry-seconds previous branch
issue #3132 fix/3132-mqtt-kafka-retained-tombstone previous branch
issue #3133 fix/3133-mqtt-v4-clean-session-persistence previous branch

Test evidence

Tests were committed first. Against develop (before the fix) the new binding-mqtt ITs failed: shouldConnectWithPublishMaximumQos1, shouldConnectWithPublishMaximumQos0 and shouldRejectWillQos2WhenPublishMaximumQos1 in server.v5.ConnectionIT. The Will check at the session reply was added test-first as well: shouldRejectWillQos2WhenSessionReplyPublishMaximumQos1 fails without the check (CONNACK is not 0x9B) and passes with it.

./mvnw clean verify -am -pl specs/binding-mqtt.spec,runtime/binding-mqtt,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka passes (BUILD SUCCESS, with checkstyle, license and jacoco checks) after the fix and the rebase onto #3135.

New scripts:

  • binding-mqtt network and application: connect.publish.maximum.qos.1, connect.publish.maximum.qos.0 (the application script sets subscribeQosMax(2) and only varies publishQosMax), connect.will.reject.will.qos.2.publish.maximum.qos.1, and connect.will.reject.will.qos.2.session.reply.publish.maximum.qos.1 (the application reads the Will before replying, so only the reply can lower the limit).
  • mqtt-kafka mqtt and kafka: session.publish.qos.max.1, session.publish.qos.max.0, run through the real proxy with options.publish.qosMax 1 and 0 and with a ${params} route.

Enforcing publishQosMax in the matcher exposed these disagreements, each resolved by review:

  • binding-mqtt client ITs (about 60 tests): the scripts expected publishQosMax(2); the implementation never set it. Implementation fixed (MqttClientFactory).
  • binding-mqtt client scripts connect.delegate.connack.properties and session.will.message.retain asserted subscribeQosMax(0) for a CONNACK Maximum QoS of 0; they now assert subscribeQosMax(2) and publishQosMax(0).
  • mqtt-kafka publish.reject.qos2 server script replied publishQosMax(2), but the proxy gives 1 for both a ${params} route and at_least_once; the client script already expected 1. Script fixed.
  • mqtt-kafka session.subscribe and session.reject.non.compacted.sessions.topic asserted 2 while their ITs run with a lowered limit (the Kafka scripts open no meta streams). Scripts now assert 1, and the duplicate @Configure(PUBLISH_MAX_QOS_NAME) with conflicting values on those two test methods is reduced to one.

Notes and follow-ups

  • The mqtt-kafka publish limit is binding-wide: one route using ${params} lowers QoS 2 for every route. Lazy QoS 2 setup per resolved topic removes the dependence on routes; tracked in mqtt-kafka: support lazy QoS 2 setup when the messages topic is resolved at PUBLISH #3148.
  • binding-mqtt and mqtt-kafka are never run against each other in one engine by the ITs, so the Will rejection at the session reply is tested against a mock application that replies after the Will data, not against the real proxy.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoXuc5cy4391QVRVKbK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mqtt-kafka: CONNACK omits Maximum QoS when QoS 2 publish is disabled

2 participants