Thank you. It worked. lCassa
On Wed, Jan 22, 2014 at 7:45 PM, Guozhang Wang <wangg...@gmail.com> wrote: > Hello, > > In your case the key's type is String, not byte array, so you need to > override the following property: > > key.serializer.class -> "kafka.serializer.StringEncoder" > > Details of the producer configs can be found: > > http://kafka.apache.org/documentation.html#producerconfigs > > > On Wed, Jan 22, 2014 at 4:51 PM, Cassa L <lcas...@gmail.com> wrote: > > > Hi all, > > I am a new user of Kafka. I tried Java example of it and it worked > great. > > Now when I tried to write to a Producer (Java) and send ByteArray to it > as > > a data, I get ClassCastException as below > > > > java.lang.ClassCastException: java.lang.String cannot be cast to [B > > at kafka.serializer.DefaultEncoder.toBytes(Encoder.scala:34) > > at > > > > > kafka.producer.async.DefaultEventHandler$$anonfun$serialize$1.apply(DefaultEventHandler.scala:128) > > at > > > > > kafka.producer.async.DefaultEventHandler$$anonfun$serialize$1.apply(DefaultEventHandler.scala:125) > > at > > > > > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233) > > at > > > > > scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233) > > at > > > > > scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34) > > at > scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:33) > > at > > scala.collection.TraversableLike$class.map(TraversableLike.scala:233) > > at scala.collection.mutable.WrappedArray.map(WrappedArray.scala:33) > > at > > > > > kafka.producer.async.DefaultEventHandler.serialize(DefaultEventHandler.scala:125) > > at > > > > > kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:52) > > at kafka.producer.Producer.send(Producer.scala:76) > > at kafka.javaapi.producer.Producer.send(Producer.scala:33) > > > > ===================== > > I am setting up Kafka properties as below - > > > > props.put("serializer.class", "kafka.serializer.DefaultEncoder"); > > props.put("partitioner.class", > > "kafka.producer.DefaultPartitioner"); > > > > ===================== > > And I am sending data to producer as mentioned below - > > KeyedMessage<String,byte[]> data = new KeyedMessage<String, > byte[]> > > ("Topic", key, bytearray ); > > producer.send(data); > > > > Can someone help me understand where actually this ClassCast problem is > > occurring? > > > > ..lCassa > > > > > > -- > -- Guozhang >