Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Kafka, mail # user - Handling Scala exceptions from ListTopicsCommand in Java


+
sggraham@... 2013-11-05, 20:56
+
Edward Capriolo 2013-11-05, 21:14
+
Edward Capriolo 2013-11-05, 21:16
+
sgg 2013-11-05, 22:24
Copy link to this message
-
Re: Handling Scala exceptions from ListTopicsCommand in Java
Jun Rao 2013-11-06, 05:12
We don't have an official client api for creating topics yet. You can try
instantiating kafka.admin.CreateTopicCommand$ and use the following method:

createTopic(zkClient: ZkClient, topic: String, numPartitions: Int = 1,
replicationFactor: Int = 1, replicaAssignmentStr: String = "")

To instantiate zkClient, do
 zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer)

Thanks,

Jun
On Tue, Nov 5, 2013 at 11:24 AM, <[EMAIL PROTECTED]> wrote:

> Hi All:
> I am trying to programmatically create Topics from a Java client.
>
> I am using a suggestion from
> http://stackoverflow.com/questions/16946778/how-can-we-create-a-topic-in-kafka-from-the-ide-using-api/18480684#18480684
>
> Essentially invoking the CreateTopicCommand.main().
>
>         String [] arguments = new String[8];
>         arguments[0] = "--zookeeper";
>         arguments[1] = "localhost:2181";
>         arguments[2] = "--replica";
>         arguments[3] = "1";
>         arguments[4] = "--partition";
>         arguments[5] = "5";
>         arguments[6] = "--topic";
>         arguments[7] = "someTopicName";
>
>         try{
>                 CreateTopicCommand.main(arguments);
>         }catch(Exception e){
>                 System.out.println("Topic someTopicName exists.");
>         }
>
> This code works fine the first time it is run (i.e. the Topic does not yet
> exist).
>
> Unfortunately, when this is run a second time, an exception is thrown from
> Scala that the Java catch block DOES NOT CATCH!
>
> I tried using the ListTopicsCommand, but there is no boolean response to
> verify if the topic already exists.
>
> Any suggestions?
>
> thanks
> sgg
>