kafka-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sunil kalva <sambarc...@gmail.com>
Subject Re: blocking KafkaProducer call
Date Wed, 01 Apr 2015 12:51:52 GMT
I am trying to simulate "sync" call using following code,

try {

    Future<RecordMetadata> send = producer.send(new
ProducerRecord<byte[],byte[]>("the-topic", "key".getBytes(),
"value".getBytes())).get();

     send.get();

    System.out.println("Time = " + (System.currentTimeMillis() - b));
} catch (Exception e) {

}

And i am using new "org.apache.kafka.clients.producer.KafkaProducer"
class for sending messages, each  message  is taking more than 100ms,
am i missing something. If i use old "kafka.javaapi.producer.Produce"
it is giving the desired throughput.

Please advice me hot to fix this.


On Tue, Mar 31, 2015 at 11:21 PM, sunil kalva <sambarcode@gmail.com> wrote:

> thanks ghenke, that was a quick response. I will test and will let you
> know if i have some questions.
>
> On Tue, Mar 31, 2015 at 11:17 PM, Grant Henke <ghenke@cloudera.com> wrote:
>
>> I think you are looking at is this section:
>>
>> > If you want to simulate a simple blocking call you can do the following:
>> >
>> > producer.send(new ProducerRecord<byte[],byte[]>("the-topic",
>> "key".getBytes(), "value".getBytes())).get();
>> >
>> > What that is doing is calling .get() on the Future returned by the send
>> method. This will block until the message is sent or an exception is
>> thrown.
>>
>> The documentation for Future is here:
>>
>> http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html#get()
>>
>> On Tue, Mar 31, 2015 at 12:30 PM, sunil kalva <sambarcode@gmail.com>
>> wrote:
>>
>> > Hi
>> > According to this
>> >
>> >
>> http://kafka.apache.org/082/javadoc/index.html?org/apache/kafka/clients/producer/KafkaProducer.html
>> > documentation, if i don't pass callback it will work as blocking call,
>> Does
>> > it mean that message will be immediately sent to kafka cluster and all
>> > possible exceptions will be throws immediately if not able to send ?
>> >
>> > --
>> > SunilKalva
>> >
>>
>>
>>
>> --
>> Grant Henke
>> Solutions Consultant | Cloudera
>> ghenke@cloudera.com | 920-980-8979
>> twitter.com/ghenke <http://twitter.com/gchenke> |
>> linkedin.com/in/granthenke
>>
>
>
>
> --
> SunilKalva
>



-- 
SunilKalva

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message