I also agree that returning a Future should never block. I have brought
this up when 0.8.2 was first released for new Java  producer.

As Oleg said, KafkaProducer can also block if metadata is not fetched. This
is probably more often than offline broker, because metadata is loaded
lazily when there is a first send attempt for the topic. In another word,
first send to a topic will always block until metadata is fetched or timed
out.

We had to handle this in our wrapper code. Basically, we check if metadata
not available, we put msg into a queue and drain the queue from a diff
thread.

Thanks,
Steven


On Tue, Mar 29, 2016 at 4:59 AM, Oleg Zhurakousky <
ozhurakou...@hortonworks.com> wrote:

> I agree and considering that send(..) method returns Future one would
> argue it must never block, otherwise what’s the point of returning Future
> if you remove user’s ability to control how long are they willing to wait
> and what to do when certain types of exception arise. Nevertheless it does
> and it happens in the very first line of code:
> // first make sure the metadata for the topic is available
> waitOnMetadata(record.topic(), this.metadataFetchTimeoutMs);
> So I am curious as well as to what is the motivation for it as we’ve seen
> the same symptoms multiple times.
> Cheers
> Oleg
> On Mar 29, 2016, at 4:31 AM, Paolo Patierno <ppatie...@live.com<mailto:
> ppatie...@live.com>> wrote:
>
> Hello,
> as documentation says, the KafkaProducer.send() method is asynchronous and
> it just returns immediately.I found out that it's not so true when the
> Kafka server it's trying to connect isn't online.Of course it happens only
> on the first send() method invocation. It means that if the Kafka server
> isn't reachable when my application starts for the first time, the send()
> method isn't so asynchronous but it blocks.I know that it's trying to
> connect to the Kafka server but why it doesn't save the message into the
> buffer and returns immediately ?Is it a behavior or a bug ?
> Thanks,Paolo
>
> Paolo PatiernoSenior Software Engineer
>
>
> Windows Embedded & IoTMicrosoft Azure Advisor
> Twitter : @ppatierno
> Linkedin : paolopatierno
> Blog : DevExperienceBlog : Embedded101
>
>
>

Reply via email to