1

I have written my own serialiser to publish a java object to a topic. I set the serializer.class property to my custom serialiser. When running the producer i get following exception. Can someone help me out?

exception

Exception in thread "main" java.lang.NoSuchMethodException: com.xxxx.CustomFileSerializer.<init>(kafka.utils.VerifiableProperties)
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getConstructor(Class.java:1825)
    at kafka.utils.CoreUtils$.createObject(CoreUtils.scala:222)
    at kafka.producer.Producer.<init>(Producer.scala:62)
    at kafka.javaapi.producer.Producer.<init>(Producer.scala:26)
    at com.xx.KafkaProducer.generateMessgaes(KafkaProducer.java:50)
    at com.xx.KafkaProducer.main(KafkaProducer.java:60)

My producer

props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("serializer.class", "com.xxxx.CustomFileSerializer");


kafka.javaapi.producer.Producer<String, FileObj> producer = new kafka.javaapi.producer.Producer<String, FileObj>(
                producerConfig);
        String key = "key1";
        KeyedMessage<String, RawFile>   record = new KeyedMessage<String, RawFile>(topic, key, file);
        producer.send(record);
        producer.close();

1 Answer 1

4

Looks like you're using the old producer with a new serializer. Old serializers took a VerifiableProperties value in their constructor. Try the new producer or use an implementation of Decoder as your serializer.

Note also that the serializer property names changed with the new producer as did the interfaces that de/serializers implement (Serializer and Deserializer instead of the old Decoder)

Sign up to request clarification or add additional context in comments.

1 Comment

I sorted out like adding a constructor with VerifiableProperties verifiableProperties parameters. May i know what is the new APIs I have to use?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.