You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Ali Akhtar <al...@gmail.com> on 2016/09/14 03:45:52 UTC

How to create a topic using the Java API / Client?

Using version 0.10.0.1, how can I create kafka topics using the java client
/ API?

Stackoverflow answers describe using kafka.admin.AdminUtils, but this class
is not included in the kafka-clients maven dependency. I also don't see the
package kafka.admin in the javadocs: http://kafka.apache.
org/0100/javadoc/index.html?org/apache/kafka/clients/
producer/KafkaProducer.html


What am I missing?

Re: How to create a topic using the Java API / Client?

Posted by Ali Akhtar <al...@gmail.com>.
I'm guessing its not possible to delete topics?

On Thu, Sep 15, 2016 at 5:43 AM, Ali Akhtar <al...@gmail.com> wrote:

> Thank you  Martin
>
> On 15 Sep 2016 3:05 am, "Mathieu Fenniak" <ma...@replicon.com>
> wrote:
>
>> Hey Ali,
>>
>> If you have auto create turned on, which it sounds like you do, and you're
>> happy with using the broker's configured partition count and replication
>> factor, then you can call "partitionsFor(String topic)" on your producer.
>> This will create the topic without sending a message to it.  I'm not sure
>> it's 100% smart, but I found it to be better than the alternatives I could
>> find. :-)
>>
>> Mathieu
>>
>>
>> On Wed, Sep 14, 2016 at 3:41 PM, Ali Akhtar <al...@gmail.com> wrote:
>>
>> > It looks like if I just send a message to a non-existent topic, it is
>> > created. But this has the downside that the first message of the topic
>> is
>> > null or otherwise invalid.
>> >
>> > Also the partition count can't be specified.
>> >
>> > Is there a way to create a topic without needing to post a null
>> message? Do
>> > I need to talk to the bash script?
>> >
>> > On Wed, Sep 14, 2016 at 8:45 AM, Ali Akhtar <al...@gmail.com>
>> wrote:
>> >
>> > > Using version 0.10.0.1, how can I create kafka topics using the java
>> > > client / API?
>> > >
>> > > Stackoverflow answers describe using kafka.admin.AdminUtils, but this
>> > > class is not included in the kafka-clients maven dependency. I also
>> don't
>> > > see the package kafka.admin in the javadocs: http://kafka.apache.
>> > > org/0100/javadoc/index.html?org/apache/kafka/clients/produce
>> > > r/KafkaProducer.html
>> > >
>> > >
>> > > What am I missing?
>> > >
>> > >
>> >
>>
>

Re: How to create a topic using the Java API / Client?

Posted by Ali Akhtar <al...@gmail.com>.
Thank you  Martin

On 15 Sep 2016 3:05 am, "Mathieu Fenniak" <ma...@replicon.com>
wrote:

> Hey Ali,
>
> If you have auto create turned on, which it sounds like you do, and you're
> happy with using the broker's configured partition count and replication
> factor, then you can call "partitionsFor(String topic)" on your producer.
> This will create the topic without sending a message to it.  I'm not sure
> it's 100% smart, but I found it to be better than the alternatives I could
> find. :-)
>
> Mathieu
>
>
> On Wed, Sep 14, 2016 at 3:41 PM, Ali Akhtar <al...@gmail.com> wrote:
>
> > It looks like if I just send a message to a non-existent topic, it is
> > created. But this has the downside that the first message of the topic is
> > null or otherwise invalid.
> >
> > Also the partition count can't be specified.
> >
> > Is there a way to create a topic without needing to post a null message?
> Do
> > I need to talk to the bash script?
> >
> > On Wed, Sep 14, 2016 at 8:45 AM, Ali Akhtar <al...@gmail.com>
> wrote:
> >
> > > Using version 0.10.0.1, how can I create kafka topics using the java
> > > client / API?
> > >
> > > Stackoverflow answers describe using kafka.admin.AdminUtils, but this
> > > class is not included in the kafka-clients maven dependency. I also
> don't
> > > see the package kafka.admin in the javadocs: http://kafka.apache.
> > > org/0100/javadoc/index.html?org/apache/kafka/clients/produce
> > > r/KafkaProducer.html
> > >
> > >
> > > What am I missing?
> > >
> > >
> >
>

Re: How to create a topic using the Java API / Client?

Posted by Mathieu Fenniak <ma...@replicon.com>.
Hey Ali,

If you have auto create turned on, which it sounds like you do, and you're
happy with using the broker's configured partition count and replication
factor, then you can call "partitionsFor(String topic)" on your producer.
This will create the topic without sending a message to it.  I'm not sure
it's 100% smart, but I found it to be better than the alternatives I could
find. :-)

Mathieu


On Wed, Sep 14, 2016 at 3:41 PM, Ali Akhtar <al...@gmail.com> wrote:

> It looks like if I just send a message to a non-existent topic, it is
> created. But this has the downside that the first message of the topic is
> null or otherwise invalid.
>
> Also the partition count can't be specified.
>
> Is there a way to create a topic without needing to post a null message? Do
> I need to talk to the bash script?
>
> On Wed, Sep 14, 2016 at 8:45 AM, Ali Akhtar <al...@gmail.com> wrote:
>
> > Using version 0.10.0.1, how can I create kafka topics using the java
> > client / API?
> >
> > Stackoverflow answers describe using kafka.admin.AdminUtils, but this
> > class is not included in the kafka-clients maven dependency. I also don't
> > see the package kafka.admin in the javadocs: http://kafka.apache.
> > org/0100/javadoc/index.html?org/apache/kafka/clients/produce
> > r/KafkaProducer.html
> >
> >
> > What am I missing?
> >
> >
>

Re: How to create a topic using the Java API / Client?

Posted by Ajay Sharma <as...@arenasolutions.com>.
You can make following setting to set partition count, etc

auto.create.topics.enable = true 		(enable auto creation of topic on the server)
num.partitions = 1 			(number of log partitions per topic)


On 9/14/16, 2:41 PM, "Ali Akhtar" <al...@gmail.com> wrote:

    It looks like if I just send a message to a non-existent topic, it is
    created. But this has the downside that the first message of the topic is
    null or otherwise invalid.
    
    Also the partition count can't be specified.
    
    Is there a way to create a topic without needing to post a null message? Do
    I need to talk to the bash script?
    
    On Wed, Sep 14, 2016 at 8:45 AM, Ali Akhtar <al...@gmail.com> wrote:
    
    > Using version 0.10.0.1, how can I create kafka topics using the java
    > client / API?
    >
    > Stackoverflow answers describe using kafka.admin.AdminUtils, but this
    > class is not included in the kafka-clients maven dependency. I also don't
    > see the package kafka.admin in the javadocs: http://kafka.apache.
    > org/0100/javadoc/index.html?org/apache/kafka/clients/produce
    > r/KafkaProducer.html
    >
    >
    > What am I missing?
    >
    >
    


Re: How to create a topic using the Java API / Client?

Posted by Ali Akhtar <al...@gmail.com>.
It looks like if I just send a message to a non-existent topic, it is
created. But this has the downside that the first message of the topic is
null or otherwise invalid.

Also the partition count can't be specified.

Is there a way to create a topic without needing to post a null message? Do
I need to talk to the bash script?

On Wed, Sep 14, 2016 at 8:45 AM, Ali Akhtar <al...@gmail.com> wrote:

> Using version 0.10.0.1, how can I create kafka topics using the java
> client / API?
>
> Stackoverflow answers describe using kafka.admin.AdminUtils, but this
> class is not included in the kafka-clients maven dependency. I also don't
> see the package kafka.admin in the javadocs: http://kafka.apache.
> org/0100/javadoc/index.html?org/apache/kafka/clients/produce
> r/KafkaProducer.html
>
>
> What am I missing?
>
>