Repository navigation
Description
Problem
A route's with.messages can contain ${params...}, so the Kafka messages topic is not known until a PUBLISH arrives and its topic name is matched. QoS 2 needs per-topic preparation before a publish to that topic can run its exactly-once handshake, and today that preparation only happens at session start, for the topics known then:
- a Kafka meta stream per route messages topic plus the retained topic, to learn partitions;
- the session's stored offsets are fetched (in-flight QoS 2 packet ids and their partitions);
- a producer (producer id and epoch) is initialized unless one is stored;
- an offset-commit stream is opened, an offset entry per partition is seeded and persisted to the sessions topic.
Nothing can prepare a topic that is first resolved at PUBLISH, so QoS 2 is unsupported for ${params...} topics. As a workaround, MqttKafkaBindingConfig.publishQosMax() returns QoS 1 for the whole binding when any route's with.messages has ${params...} (routes with static topics lose QoS 2 too), and MqttKafkaPublishFactory applies the same value regardless of the route matched by the publish topic. That value also flows into the CONNACK Maximum QoS (MQTT 5.0 [MQTT-3.2.2-9]) and the Will QoS check.
Proposal
Support lazy QoS 2 setup: when a QoS 2 publish first resolves a messages topic, fetch that topic's partitions, seed offset entries for them under the session's existing producer id, and persist them with the session offsets, so reconnect recovery covers topics added mid-session.
Once that works, QoS 2 no longer depends on routes: the publish limit is just the configured publish.qosMax, and the ${params} special case in publishQosMax() is removed. A route-aware limit is not needed as separate work.
Points to settle in the design
- The first publish on a new topic waits on a Kafka metadata round trip; the PUBREC must wait for it.
- Reconnect recovery reads stored offsets, so entries for lazily added topics must be re-fetched and re-seeded the same way.
- The offset-commit and offset-fetch streams are opened once per session and must accept entries being added mid-session.
- Whether static-topic routes keep preparing at session start or also move to the lazy path.
- Param values can be unbounded; decide whether to cap topics per session or how to age out entries.
Test plan (test-first)
mqtt/kafka script pairs for QoS 2 publish through a route with ${params}: first publish on a topic, a second topic in the same session, and reconnect with in-flight QoS 2 on a lazily resolved topic. Existing static-topic QoS 2 scripts must keep passing.
Activity
[-]mqtt-kafka: prepare QoS 2 lazily per resolved messages topic instead of limiting publish QoS by route[/-][+]mqtt-kafka: prepare QoS 2 lazily per messages topic instead of eagerly at session start[/+][-]mqtt-kafka: prepare QoS 2 lazily per messages topic instead of eagerly at session start[/-][+]mqtt-kafka: support lazy QoS 2 setup when the messages topic is resolved at PUBLISH[/+]