kafka-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramesh K <krame...@gmail.com>
Subject Re: How to send serialized object in Kafka Producer
Date Fri, 05 Dec 2014 13:01:40 GMT
Dear Guozhang,

Sorry for the late reply.

Please see the sample code which i written to send the bean object.

import java.util.Properties;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public class KafkaProducerBean {

final static String TOPIC = "*alarm*";
public static void main(String[] args) {

Properties properties = new Properties();
        properties.put("metadata.broker.list","x.x.x.227:9092");
        properties.put("serializer.class","TestBean");

        ProducerConfig producerConfig = new ProducerConfig(properties);
        kafka.javaapi.producer.Producer<String,TestBean> producer = new
kafka.javaapi.producer.Producer<String, TestBean>(producerConfig);

        TestBean tb = new TestBean();
        tb.setName("Olive");
        tb.setAge(25);

        KeyedMessage<String, TestBean> message =new KeyedMessage<String,
TestBean>(*TOPIC*, tb);
        producer.send(message);
        producer.close();
}

}


Error :
Exception in thread "main" java.lang.NoSuchMethodException:
TestBean.<init>(kafka.utils.VerifiableProperties)


Thanks
Ramesh K


On Wed, Dec 3, 2014 at 1:03 AM, Guozhang Wang <wangguoz@gmail.com> wrote:

> Ramesh,
>
> Which producer are you using in 0.8.1? kafka.api.producer or
> org.apache.kafka.clients.producer?
>
> Guozhang
>
> On Tue, Dec 2, 2014 at 2:12 AM, Ramesh K <kramesh7@gmail.com> wrote:
>
> > Hi,
> >
> > I have written the basic program to send String or byte[] messages to
> > consumer from producer by using java & Kafka 0.8.1 .
> > It Works perfectly.But i wanted to send serialized object(Java Bean
> > Object).
> >
> > Is it possible to send the serialized object from producer to consumer?
> >
> > if possible, please share the ideas/samples.
> >
> > Thanks in advance..
> > Ramesh Kasi
> >
>
>
>
> --
> -- Guozhang
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message