Kafka, mail # dev - parittioner runtime error with kafka 0.8 - 2013-01-18, 01:29
 Search Hadoop and all its subprojects:

Switch to Plain View
Copy link to this message
parittioner runtime error with kafka 0.8
I defined a customized partitioner:

class ExpertSearchCollectionPartitioner implements Partitioner<Long> {


  public int partition(Long key, int numPartitions) {

    System.out.print("    partition: " + key + ", " + numPartitions +
", "+ (key.hashCode() % numPartitions) +

    return (int) (key % (long) numPartitions);


and in the producer:

props.put("partitioner.class",  ExpertSearchCollectionPartitioner.class

producer = new Producer<Long, String>(new ProducerConfig(props));

producer.send(new KeyedMessage<Long, String>(


              new Long(1),

              new String("I love kafka" + count)));
however, when I run the producer, I always got the following error:
Exception in thread "main" java.lang.NoSuchMethodException:

at java.lang.Class.getConstructor0(Class.java:2721)

at java.lang.Class.getConstructor(Class.java:1674)

at kafka.utils.Utils$.createObject(Utils.scala:457)

at kafka.producer.Producer.<init>(Producer.scala:61)

at kafka.javaapi.producer.Producer.<init>(Producer.scala:25)



May I ask what I am missing? Is there anywhere an example java code to
customize the partitioner?

Thanks alot!

Jay Kreps 2013-01-18, 03:09
Jane Wang 2013-01-18, 03:58
Jane Wang 2013-01-18, 17:26
Jay Kreps 2013-01-18, 21:21
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB