[
https://issues.apache.org/jira/browse/CAMEL-23883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18093853#comment-18093853
]
Matteo Minin commented on CAMEL-23883:
--------------------------------------
Hi, I'd like to work on this issue (it would be my very first contribution).
I've investigated the issue and I think I found the issue, I'd appreciate
guidance on the preferred fix direction before opening a PR.
*Identified Cause:* Jackson's _JsonNode_ implements {_}Iterable<JsonNode>{_},
so a scalar value node such as `IntNode` (e.g. the output of
{_}transform().jq(".my-value"){_}) is considered an iterable with empty
iterator.
The _KafkaProducer.process() then iterates on the empty iterator, that results
in never calling the KafkaProducer.send() method and quietly returning"._
*Proposed Solution:*
Exclude Jackson value nodes (non collections) from {_}isIterable(){_}, so
scalar nodes take the single-message path and go through normal serialization.
{*}Note{*}: this fixes the reported Jackson case, but the same silent drop
could recur for any type that is Iterable yet yields an empty iterator.
It might be worth deciding, in this PR or a future one, whether a warning
(maybe in DEBUG level) or other safeguard should be added.
I'd appreciate any feedback or better ideas.
Could this be assigned to me? Thanks!
> Camel Kafka producer fails silently on unexpected message body type
> -------------------------------------------------------------------
>
> Key: CAMEL-23883
> URL: https://issues.apache.org/jira/browse/CAMEL-23883
> Project: Camel
> Issue Type: Bug
> Components: camel-kafka
> Affects Versions: 4.21.0
> Reporter: Christoph Deppisch
> Priority: Major
> Fix For: 4.22.0
>
>
> The Kafka message producer fails silently in
> {code:java}
> to("kafka:my-topic"){code}
> when the Exchange message body has an unexpected type.
>
> For instance when transforming the message body like in
> {code:java}
> transform().jq(".my-value"){code}
> the result can be a message body of type
> {_}*com.fasterxml.jackson.databind.node.IntNode*{_}{*}{*}
> For some reason (I guess because of a missing Kafka serialization strategy)
> the Kafka producer is not able to handle the message body type and the Camel
> route fails silently to send the Kafka message. The Camel route does not
> report any error in this situation and the Kafka event is just skipped
> without further notice.
> We should at least make sure to raise an exception here instead of failing
> silently.
> You can reproduce the behavior with this example project:
> [https://github.com/citrusframework/citrus-quarkus-examples/blob/main/apache-camel/camel-mqtt]
> A workaround that can be seen in this example project. The workaround is to
> explicitly convert the _*com.fasterxml.jackson.databind.node.IntNode*_
> message body into a supported type such as Integer.class with
> {code:java}
> convertBodyTo(Integer.class){code}
> With that the Kafka event is sent as expected.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)