1. Use the command line method:
[lch@linux129 bin]$./kafka-topics.sh--create--zookeeper hadoop221:2181,hadoop222:2181--replication-factor 2-- Partitions 2--topic test_ttt parameter description:--replication-factor: Indicates the number of copies, written here 2, indicating there will be two copies--partitions: indicates there will be two par Tition, shown in log logs, is two folders
This is the test_ttt-0 and test_ttt-1 Note: The leader node above is two files, if it is from the node above, there may be only one--topic:topic name
2. How to use Java code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class kafkaadmin{ public static void Main (string[] args) { string[] arrys = new string[6]; arrys[0] = "--replication-factor"; arrys[1] = "1"; arrys[2] = "--partitions"; arrys[3] = "1"; arrys[4] = "--topic"; arrys[5] = "EFGH"; zkclient client = new zkclient (" 192.168.8.222:2181 ", 30000, 30000); Client.setzkserializer (new ZkstriNgserialize ()); //Must be added Zkserializer topiccommandoptions opts = new topiccommandoptions (Arrys); topiccommand.createtopic (client, opts); }} |
Not too familiar with Scala, don't know how to invoke the object in Scala, so according to Zkstringserializer in Scala, we implemented a
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public class Zkstringserialize implements Zkserializer {@Override public byte [] Serialize (Object data) t Hrows Zkmarshallingerror { |