Created
June 19, 2014 03:32
-
-
Save darionyaphet/aef88104c7704c65e1c8 to your computer and use it in GitHub Desktop.
ProducerMultPartition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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