You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Webster <we...@sial.com> on 2017/02/07 22:56:18 UTC

Kafka Producer Serialization Error

I am new to camel and kafka.
I am using Camel 2.18.2 with Kafka 0.10.1.1

I am getting this error and don't understand why:
org.apache.kafka.common.errors.SerializationException: Can't convert value
of class [B to class org.apache.kafka.common.serialization.StringSerializer
specified in value.serializer


I have the following route:
from("direct://toEnrichEmail")
.routeId(routeId).marshal().json(JsonLibrary.Jackson, Map.class)
.log(LoggingLevel.INFO, "Sending to Kafka: ${body}")
.to("kafka:localhost:9092?topic=enrich-email&requestRequiredAcks=-1");

The code that actually sends to the route:
		ProducerTemplate template = kafkaProducerFactory.getProducerTemplate();
		logger.debug("Sending message type: {}, to uri: {}, route: {}",
wimsConfiguration.getMessageType(), 
				wimsConfiguration.getDirectUri(), wimsConfiguration.getRouteName());
		Map<String,Object>headers = new HashMap<>(); // added because the examples
do
		headers.put(KafkaConstants.PARTITION_KEY, 0);
		headers.put(KafkaConstants.KEY, "1");
		template.sendBodyAndHeaders(wimsConfiguration.getDirectUri(),
wimsConfiguration.getWimsMessage(), headers);


The log message in the route shows that the message is a proper JSON string,
the default serializer is string, So why is it complaining that it cannot
serialize?

I looked through the camel kafka component test cases and this looks like it
should work




--
View this message in context: http://camel.465427.n5.nabble.com/Kafka-Producer-Serialization-Error-tp5793630.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Kafka Producer Serialization Error

Posted by Webster <we...@sial.com>.
thanks, converting the json string to a string makes Kafka happy.

Seems like a defect that this should be required



--
View this message in context: http://camel.465427.n5.nabble.com/Kafka-Producer-Serialization-Error-tp5793630p5793702.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Kafka Producer Serialization Error

Posted by Ravindra Godbole <go...@gmail.com>.
I am also not able to understand the error but after this change it works.

.routeId(routeId).marshal().json(JsonLibrary.Jackson,
Map.class).convertBodyTo(String.class)

On Wed, Feb 8, 2017 at 4:26 AM, Webster <we...@sial.com> wrote:

> I am new to camel and kafka.
> I am using Camel 2.18.2 with Kafka 0.10.1.1
>
> I am getting this error and don't understand why:
> org.apache.kafka.common.errors.SerializationException: Can't convert value
> of class [B to class org.apache.kafka.common.
> serialization.StringSerializer
> specified in value.serializer
>
>
> I have the following route:
> from("direct://toEnrichEmail")
> .routeId(routeId).marshal().json(JsonLibrary.Jackson, Map.class)
> .log(LoggingLevel.INFO, "Sending to Kafka: ${body}")
> .to("kafka:localhost:9092?topic=enrich-email&requestRequiredAcks=-1");
>
> The code that actually sends to the route:
>                 ProducerTemplate template = kafkaProducerFactory.
> getProducerTemplate();
>                 logger.debug("Sending message type: {}, to uri: {}, route:
> {}",
> wimsConfiguration.getMessageType(),
>                                 wimsConfiguration.getDirectUri(),
> wimsConfiguration.getRouteName());
>                 Map<String,Object>headers = new HashMap<>(); // added
> because the examples
> do
>                 headers.put(KafkaConstants.PARTITION_KEY, 0);
>                 headers.put(KafkaConstants.KEY, "1");
>                 template.sendBodyAndHeaders(wimsConfiguration.
> getDirectUri(),
> wimsConfiguration.getWimsMessage(), headers);
>
>
> The log message in the route shows that the message is a proper JSON
> string,
> the default serializer is string, So why is it complaining that it cannot
> serialize?
>
> I looked through the camel kafka component test cases and this looks like
> it
> should work
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Kafka-Producer-Serialization-Error-tp5793630.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
- Ravi

*[ View My Youtube Channel ] <https://www.youtube.com/c/RavindraGodbole>*

Phone: +91 *98 509 760 91*