Kafka Learning--the creation of topic

Source: Internet
Author: User
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 {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.