Skip to content

fix(binding-mqtt-kafka): keep a trailing empty topic level when splitting topic names and filters - #3274

Merged
jfallows merged 5 commits into
fix/3205-mqtt-kafka-clean-start-qos-maxfrom
fix/3260-mqtt-kafka-trailing-empty-level
Nov 17, 2026
Merged

jfallows merged 5 commits into
fix/3205-mqtt-kafka-clean-start-qos-maxfrom
fix/3260-mqtt-kafka-trailing-empty-level

Conversation

@jfallows

@jfallows jfallows commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Both the publish and the subscribe side of mqtt-kafka split topics with String.split("/"), which drops a trailing empty string. A topic sensor/ was therefore published with the Kafka filter headers [sensor], and a filter sensor/ was subscribed as [sensor]. As a result a subscriber of sensor could receive the topic sensor/, and a filter sensor/+ ([sensor, skip]) could never match it. The will message topic is split the same way.

The change splits with a negative limit (split("/", -1)) in MqttKafkaPublishFactory (topic name headers), MqttKafkaSubscribeFactory (buildHeaders) and MqttKafkaSessionFactory (will message topic headers), so every level, including a trailing zero-length one, becomes a filter header value. This mirrors how the same binding already keeps the trailing level in the reply-filter header (MqttKafkaPublishFactory.addFiltersHeader) and in MqttKafkaConditionMatcher, which splits with a positive limit.

This PR is stacked on #3273 (base fix/3205-mqtt-kafka-clean-start-qos-max).

Other splits of topic strings in the binding

Searched split( in runtime/binding-mqtt-kafka/src/main and runtime/binding-mqtt/src/main:

  • Fixed, same defect: MqttKafkaPublishFactory (topic name), MqttKafkaSubscribeFactory (filter), MqttKafkaSessionFactory (will topic).
  • Already keeps empty levels, unchanged: MqttKafkaConditionMatcher (split("/", 2)), the reply-filter header loops in MqttKafkaPublishFactory and MqttKafkaSessionFactory (indexOfByte based).
  • Not topic strings, unchanged: the split("::") calls that parse configured method names in MqttKafkaConfiguration and MqttConfiguration.

Specification statements (read from the OASIS text)

  • MQTT 5.0 4.7.1.1 and MQTT 3.1.1 4.7.1.1: "Topic level separators can appear anywhere in a Topic Filter or Topic Name. Adjacent Topic level separators indicate a zero-length topic level."
  • MQTT 5.0 4.7.1.3 and MQTT 3.1.1 4.7.1.3 (non-normative comment): "because the single-level wildcard matches only a single level, sport/+ does not match sport but it does match sport/."

Read in full: 4.7.1.1 to 4.7.1.3 of both texts, and the start of 4.7.2. Not read: the rest of Chapter 4, and the Kafka protocol documentation (the header matching involved is internal to the Zilla Kafka cache).

Test evidence

  • Added script pairs publish.topic.trailing.empty.level, subscribe.topic.filter.trailing.empty.level and session.will.message.topic.trailing.empty.level (mqtt and kafka sides), with methods in the existing MqttIT, KafkaIT, MqttKafkaPublishProxyIT, MqttKafkaSubscribeProxyIT and MqttKafkaSessionProxyIT. No new IT classes.
  • The tests were committed before each change. Run with verify under a 600 s timeout against the unfixed code, the three new proxy ITs fail because the Kafka zilla:filter headers lack the trailing empty value, while shouldSendOneMessage, shouldFilterSingleLevelWildcard and shouldSendWillMessageOnAbort pass.
  • After the changes: specs/binding-mqtt-kafka.spec (clean verify, module checks on, 299 tests in MqttIT and KafkaIT) and runtime/binding-mqtt-kafka (clean verify, module checks on, 172 integration tests) pass, and the new methods ran in both.
  • The existing subscribe.topic.filter.single.level.wildcard script already expected [sensor, skip] for sensor/+ and passes before and after, so the sensor/+ half of the issue is the publish side losing the trailing level.

Not delivered

  • No test runs the Kafka cache matching end to end (publish sensor/, deliver to a subscriber of sensor or sensor/+); the ITs assert the headers the binding emits.
  • A topic of just / is covered by the same change but has no dedicated script.
  • The cache-skipped rebuild of the whole reactor did not complete locally (NOTICE check of the build module, unrelated to this change); the touched modules were rebuilt and verified as described above.

Fixes #3260

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoXYN9cNKpG48feM66S

…sh and subscribe

A topic name or filter ending in a topic level separator has a trailing
zero-length topic level (MQTT 5.0 4.7.1.1, MQTT 3.1.1 4.7.1.1), so "sensor/"
and "sensor" are different topics. Add script pairs and proxy ITs where a
publish to "sensor/" and a subscription to "sensor/" carry the empty level in
the Kafka filter headers.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXYN9cNKpG48feM66S
…ting topic names and filters

String.split("/") drops trailing empty strings, so "sensor/" was published and
subscribed as "sensor". Split with a negative limit so each topic level, including
a trailing zero-length one, becomes a Kafka filter header value (MQTT 5.0 4.7.1.1,
MQTT 3.1.1 4.7.1.1). This matches how the reply-filter header already keeps the
trailing level.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXYN9cNKpG48feM66S
…l message topic

The will message topic is delivered to Kafka with one filter header per topic
level, so a will topic ending in a topic level separator must carry the
trailing zero-length level (MQTT 5.0 4.7.1.1, MQTT 3.1.1 4.7.1.1).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXYN9cNKpG48feM66S
…l message topic

Split the will message topic with a negative limit so a trailing zero-length
topic level becomes a filter header value, as for published topics and
subscribed filters (MQTT 5.0 4.7.1.1, MQTT 3.1.1 4.7.1.1).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoXYN9cNKpG48feM66S
@jfallows
jfallows added this pull request to stack #3296 November 16, 2026 23:22
…qos-max' into fix/3260-mqtt-kafka-trailing-empty-level
@jfallows
jfallows merged commit c4927b4 into develop Nov 17, 2026
16 checks passed
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: a trailing empty topic level is lost when topic names and filters are split

2 participants