You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by dhiraj prajapati <dh...@gmail.com> on 2015/04/12 09:38:05 UTC

Some queries about java api for kafka producer

Hi,
I want to send data to apache kafka using the java api of the kafka
producer. The data will be in high volume, of the order of more than 5
thousand messages per second.
Please help me with the following queries:

1. Should I create only one producer object for the entire app and use the
same object to send all the messages and then close the producer in the
end? Or should I create a producer object for every message to be sent and
close the producer connection after sending each message?

2. Does the producer api inherently use a pool of Producer objects? If yes,
what is the default size of the pool and is it configurable?

Thanks in advance,
Dhiraj Prajapati

Re: Some queries about java api for kafka producer

Posted by dhiraj prajapati <dh...@gmail.com>.
Thanks a lot
On 13 Apr 2015 06:08, "Manoj Khangaonkar" <kh...@gmail.com> wrote:

> Clarification. My answer applies to the new producer API in 0.8.2.
>
> regards
>
> On Sun, Apr 12, 2015 at 4:00 PM, Manoj Khangaonkar <kh...@gmail.com>
> wrote:
>
> > Hi,
> >
> > For (1) from the java docs "The producer is *thread safe* and should
> > generally be shared among all threads for best performance"
> >
> > (2) (1) implies no pool is necessary.
> >
> > regards
> >
> > On Sun, Apr 12, 2015 at 12:38 AM, dhiraj prajapati <dhirajpraj@gmail.com
> >
> > wrote:
> >
> >> Hi,
> >> I want to send data to apache kafka using the java api of the kafka
> >> producer. The data will be in high volume, of the order of more than 5
> >> thousand messages per second.
> >> Please help me with the following queries:
> >>
> >> 1. Should I create only one producer object for the entire app and use
> the
> >> same object to send all the messages and then close the producer in the
> >> end? Or should I create a producer object for every message to be sent
> and
> >> close the producer connection after sending each message?
> >>
> >> 2. Does the producer api inherently use a pool of Producer objects? If
> >> yes,
> >> what is the default size of the pool and is it configurable?
> >>
> >> Thanks in advance,
> >> Dhiraj Prajapati
> >>
> >
> >
> >
> > --
> > http://khangaonkar.blogspot.com/
> >
>
>
>
> --
> http://khangaonkar.blogspot.com/
>

Re: Some queries about java api for kafka producer

Posted by Manoj Khangaonkar <kh...@gmail.com>.
Clarification. My answer applies to the new producer API in 0.8.2.

regards

On Sun, Apr 12, 2015 at 4:00 PM, Manoj Khangaonkar <kh...@gmail.com>
wrote:

> Hi,
>
> For (1) from the java docs "The producer is *thread safe* and should
> generally be shared among all threads for best performance"
>
> (2) (1) implies no pool is necessary.
>
> regards
>
> On Sun, Apr 12, 2015 at 12:38 AM, dhiraj prajapati <dh...@gmail.com>
> wrote:
>
>> Hi,
>> I want to send data to apache kafka using the java api of the kafka
>> producer. The data will be in high volume, of the order of more than 5
>> thousand messages per second.
>> Please help me with the following queries:
>>
>> 1. Should I create only one producer object for the entire app and use the
>> same object to send all the messages and then close the producer in the
>> end? Or should I create a producer object for every message to be sent and
>> close the producer connection after sending each message?
>>
>> 2. Does the producer api inherently use a pool of Producer objects? If
>> yes,
>> what is the default size of the pool and is it configurable?
>>
>> Thanks in advance,
>> Dhiraj Prajapati
>>
>
>
>
> --
> http://khangaonkar.blogspot.com/
>



-- 
http://khangaonkar.blogspot.com/

Re: Some queries about java api for kafka producer

Posted by Manoj Khangaonkar <kh...@gmail.com>.
Hi,

For (1) from the java docs "The producer is *thread safe* and should
generally be shared among all threads for best performance"

(2) (1) implies no pool is necessary.

regards

On Sun, Apr 12, 2015 at 12:38 AM, dhiraj prajapati <dh...@gmail.com>
wrote:

> Hi,
> I want to send data to apache kafka using the java api of the kafka
> producer. The data will be in high volume, of the order of more than 5
> thousand messages per second.
> Please help me with the following queries:
>
> 1. Should I create only one producer object for the entire app and use the
> same object to send all the messages and then close the producer in the
> end? Or should I create a producer object for every message to be sent and
> close the producer connection after sending each message?
>
> 2. Does the producer api inherently use a pool of Producer objects? If yes,
> what is the default size of the pool and is it configurable?
>
> Thanks in advance,
> Dhiraj Prajapati
>



-- 
http://khangaonkar.blogspot.com/