gnodet-bot commented on code in PR #26890:
URL: https://github.com/apache/camel/pull/26890#discussion_r4103051384
##########
components/camel-hivemq/src/main/java/org/apache/camel/component/hivemq/HiveMQConsumer.java:
##########
@@ -79,9 +80,19 @@ protected void doStop() throws Exception {
private void onMessage(Mqtt5Publish publish) {
Exchange exchange = createExchange(false);
exchange.getIn().setBody(publish.getPayloadAsBytes());
- exchange.getIn().setHeader(HiveMQConstants.MQTT_TOPIC,
publish.getTopic().toString());
- exchange.getIn().setHeader(HiveMQConstants.MQTT_QOS, publish.getQos());
- exchange.getIn().setHeader(HiveMQConstants.MQTT_RETAINED,
publish.isRetain());
+ HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
+ String topic = publish.getTopic().toString();
+ if (!strategy.applyFilterToExternalHeaders(HiveMQConstants.MQTT_TOPIC,
topic, exchange)) {
+ exchange.getIn().setHeader(HiveMQConstants.MQTT_TOPIC, topic);
+ }
+ Object qos = publish.getQos();
+ if (!strategy.applyFilterToExternalHeaders(HiveMQConstants.MQTT_QOS,
qos, exchange)) {
+ exchange.getIn().setHeader(HiveMQConstants.MQTT_QOS, qos);
+ }
+ boolean retained = publish.isRetain();
+ if
(!strategy.applyFilterToExternalHeaders(HiveMQConstants.MQTT_RETAINED,
retained, exchange)) {
+ exchange.getIn().setHeader(HiveMQConstants.MQTT_RETAINED,
retained);
+ }
Review Comment:
🔴 **Critical — breaks consumer with default strategy.**
`DefaultHeaderFilterStrategy` initializes `inFilterStartsWith` to `{"Camel",
"camel"}` with `filterOnMatch = true`. So
`applyFilterToExternalHeaders("CamelHiveMQTopic", ...)` matches the `"Camel"`
prefix and returns `true` (= filtered). Same for `CamelHiveMQQos` and
`CamelHiveMQRetained`.
With the default configuration, **none of these three headers will ever be
set on the Exchange**. Downstream routes relying on
`${header.CamelHiveMQTopic}` will silently get null.
The camel-nats pattern (cited in the PR body) is different: it applies the
filter only to *user-supplied NATS message headers* (`msg.getHeaders()` —
arbitrary key-value pairs attached by the publisher), NOT to its own
`CamelNats*` protocol metadata headers. Those are set directly without
filtering:
```java
// camel-nats — protocol metadata set DIRECTLY (no filter)
exchange.getIn().setHeader(NatsConstants.NATS_REPLY_TO, msg.getReplyTo());
exchange.getIn().setHeader(NatsConstants.NATS_SID, msg.getSID());
exchange.getIn().setHeader(NatsConstants.NATS_SUBJECT, msg.getSubject());
// ...
// Only user-supplied headers go through the filter:
msg.getHeaders().entrySet().forEach(entry -> {
if (!strategy.applyFilterToExternalHeaders(entry.getKey(),
entry.getValue(), exchange)) {
exchange.getIn().setHeader(entry.getKey(), entry.getValue().get(0));
}
});
```
Since HiveMQ's consumer only sets 3 fixed protocol-derived headers (not
user-supplied data), and doesn't propagate MQTT5 user properties, the correct
fix is to **revert these lines to the original direct `setHeader` calls**.
If the goal is to add filtering infrastructure for future use (e.g., when
MQTT5 user properties propagation is added), keep the
`HeaderFilterStrategyAware` plumbing in the endpoint/configuration but don't
apply it to these protocol-derived headers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]