[ 
https://issues.apache.org/jira/browse/CAMEL-8790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14628809#comment-14628809
 ] 

Mark Mindenhall commented on CAMEL-8790:
----------------------------------------

[~njiang], [~davsclaus]: I would really like to have this in 2.15.3.  I think 
this is definitely more of a fix than a new feature.  The camel-kafka component 
didn't support kafka's {{DefaultEncoder}} prior to this patch.  This would be 
comparable to the camel-http4 component supporting https (non-default), but not 
http (default).   

So prior to this patch, the only way to use the component was to specify 
{{serializerClass=kafka.serializer.StringEncoder}}.  Leaving 
{{serializerClass}} unspecified would result in an error.  This can be verified 
by removing the {{serializerClass}} option in 
{{org.apache.camel.component.kafka.KafkaProducerFullTest}}, then running the 
test.  

With this patch, leaving {{serializerClass}} unspecified will use the 
{{DefaultEncoder}}.  Since {{serializerClass}} previously always had to be 
specified (and specified as {{kafka.serializer.StringEncoder}}) for the 
component to work, the behavior is unchanged for anyone using the component in 
their project.  Also note that all of the existing tests still pass with this 
patch, and I have added new tests for the {{DefaultEncoder}}.

Thanks,
Mark


> Kafka producer hard coded to use Strings
> ----------------------------------------
>
>                 Key: CAMEL-8790
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8790
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-kafka
>    Affects Versions: 2.14.2, 2.15.2, 2.16.0
>            Reporter: Mark Mindenhall
>            Assignee: Willem Jiang
>             Fix For: 2.16.0
>
>         Attachments: 
> 0001-CAMEL-8790-Fix-for-Kafka-producer-hard-coded-to-use-.patch
>
>
> Kafka natively supports two encoders for messages:
> # {{kafka.serializer.DefaultEncoder}} - encodes as byte arrays
> # {{kafka.serializer.StringEncoder}} - encodes as Strings
> Camel-kafka exposes settings to select the encoder (({{serializerClass}} and 
> {{keySerializerClass}}), but the 
> {{org.apache.camel.component.kafka.KafkaProducer}} class hard-codes String 
> for both the key and value types.  This results in a {{ClassCastException}} 
> when using the {{DefaultDecoder}}.
> The attached patch fixes this as follows (conforming to kafka itself):
> * If no {{serializerClass}} option is specified, the {{DefaultDecoder}} is 
> used.
> * If no {{keySerializerClass}} option is specified, the same encoder as 
> {{serializerClass}} is used
> This fix shouldn't break any existing code, as there was not previously a 
> default setting (i.e., {{StringEncoder}} always had to be specified).
> I created the patch against master, but it should backport easily to 2.15.x 
> and 2.14.x.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to