Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Kafka >> mail # user >> Handling Scala exceptions from ListTopicsCommand in Java


Copy link to this message
-
Re: Handling Scala exceptions from ListTopicsCommand in Java
Maybe try catching RuntimeException
On Tue, Nov 5, 2013 at 2:24 PM, <[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
>

 
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB