Skip to content

Instantly share code, notes, and snippets.

@darionyaphet
Created June 19, 2014 03:32
Show Gist options
  • Save darionyaphet/aef88104c7704c65e1c8 to your computer and use it in GitHub Desktop.
Save darionyaphet/aef88104c7704c65e1c8 to your computer and use it in GitHub Desktop.
ProducerMultPartition.java
import java.util.Properties;
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;
public class ProducerMultPartition {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("metadata.broker.list", "localhost:9092");
properties.put("serializer.class", "kafka.serializer.StringEncoder");
ProducerConfig config = new ProducerConfig(properties);
Producer<String, String> producer = new Producer<String, String>(config);
for (int index = 0; index < 100; index++) {
String partition = System.currentTimeMillis() % 2 + "";
producer.send(new KeyedMessage<String, String>(
"topic.mult.partitions", partition, "Message_" + index));
}
producer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment