Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

** PLEASE NOTE ** The recommended producer is from latest stable release using the new Java producer http://kafka.apache.org/082/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html

 

Once you have confirmed you have a basic Kafka cluster setup (see 0.8 Quick Start) it is time to write some code!

...

Code Block
import kafka.producer.Partitioner;
import kafka.utils.VerifiableProperties;

public class SimplePartitioner implements Partitioner<String>Partitioner {
    public SimplePartitioner (VerifiableProperties props) {

    }

    public int partition(StringObject key, int a_numPartitions) {
        int partition = 0;
        String stringKey = (String) key;
        int offset = keystringKey.lastIndexOf('.');
        if (offset > 0) {
           partition = Integer.parseInt( keystringKey.substring(offset+1)) % a_numPartitions;
        }
       return partition;
  }

}

...