You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Rahul Amaram <ra...@vizury.com> on 2014/11/27 16:48:36 UTC

Does adding ConsumerTimeoutException make the code more robust?

Hi,

I am just wondering if the below snippet

ConsumerIterator<byte[], byte[]) it = ...

while (True)
     try {
         while (it.hasNext()) {
         ...
         ...
         ...
     } catch (ConsumerTimeoutException e) {
         // do nothing
     }
}

would be more robust than

while(it.hasNext()) {
...
...
...
}

i.e. by setting a consumer timeout, catching it and again just waiting 
for the next message make it more robust?

Regards,
Rahul.

Re: Does adding ConsumerTimeoutException make the code more robust?

Posted by Ewen Cheslack-Postava <me...@ewencp.org>.
No, hasNext will return immediately if data is available. The consumer
timeout is only helpful if your application can't safely block on the
iterator indefinitely.

-Ewen

On Sat, Nov 29, 2014, at 08:35 PM, Rahul Amaram wrote:
> Yes, I have configured consumer timeout config.
> 
> Let me put my query other way. Is it possible that it.hasNext() could be 
> blocked even when there are messages available, In which case using 
> Consumer Timeout could help?
> 
> Thanks,
> Rahul.
> 
> On Saturday 29 November 2014 09:56 PM, Jun Rao wrote:
> > By default, it.hasNext() blocks when there is no more message to consume.
> > So catching ConsumerTimeoutException doesn't make any difference. You only
> > need to handle ConsumerTimeoutException if you have customized the consumer
> > timeout config.
> >
> > Thanks,
> >
> > Jun
> >
> > On Thu, Nov 27, 2014 at 7:48 AM, Rahul Amaram <ra...@vizury.com>
> > wrote:
> >
> >> Hi,
> >>
> >> I am just wondering if the below snippet
> >>
> >> ConsumerIterator<byte[], byte[]) it = ...
> >>
> >> while (True)
> >>      try {
> >>          while (it.hasNext()) {
> >>          ...
> >>          ...
> >>          ...
> >>      } catch (ConsumerTimeoutException e) {
> >>          // do nothing
> >>      }
> >> }
> >>
> >> would be more robust than
> >>
> >> while(it.hasNext()) {
> >> ...
> >> ...
> >> ...
> >> }
> >>
> >> i.e. by setting a consumer timeout, catching it and again just waiting for
> >> the next message make it more robust?
> >>
> >> Regards,
> >> Rahul.
> >>
> 

Re: Does adding ConsumerTimeoutException make the code more robust?

Posted by Rahul Amaram <ra...@vizury.com>.
Yes, I have configured consumer timeout config.

Let me put my query other way. Is it possible that it.hasNext() could be 
blocked even when there are messages available, In which case using 
Consumer Timeout could help?

Thanks,
Rahul.

On Saturday 29 November 2014 09:56 PM, Jun Rao wrote:
> By default, it.hasNext() blocks when there is no more message to consume.
> So catching ConsumerTimeoutException doesn't make any difference. You only
> need to handle ConsumerTimeoutException if you have customized the consumer
> timeout config.
>
> Thanks,
>
> Jun
>
> On Thu, Nov 27, 2014 at 7:48 AM, Rahul Amaram <ra...@vizury.com>
> wrote:
>
>> Hi,
>>
>> I am just wondering if the below snippet
>>
>> ConsumerIterator<byte[], byte[]) it = ...
>>
>> while (True)
>>      try {
>>          while (it.hasNext()) {
>>          ...
>>          ...
>>          ...
>>      } catch (ConsumerTimeoutException e) {
>>          // do nothing
>>      }
>> }
>>
>> would be more robust than
>>
>> while(it.hasNext()) {
>> ...
>> ...
>> ...
>> }
>>
>> i.e. by setting a consumer timeout, catching it and again just waiting for
>> the next message make it more robust?
>>
>> Regards,
>> Rahul.
>>


Re: Does adding ConsumerTimeoutException make the code more robust?

Posted by Jun Rao <ju...@gmail.com>.
By default, it.hasNext() blocks when there is no more message to consume.
So catching ConsumerTimeoutException doesn't make any difference. You only
need to handle ConsumerTimeoutException if you have customized the consumer
timeout config.

Thanks,

Jun

On Thu, Nov 27, 2014 at 7:48 AM, Rahul Amaram <ra...@vizury.com>
wrote:

>
> Hi,
>
> I am just wondering if the below snippet
>
> ConsumerIterator<byte[], byte[]) it = ...
>
> while (True)
>     try {
>         while (it.hasNext()) {
>         ...
>         ...
>         ...
>     } catch (ConsumerTimeoutException e) {
>         // do nothing
>     }
> }
>
> would be more robust than
>
> while(it.hasNext()) {
> ...
> ...
> ...
> }
>
> i.e. by setting a consumer timeout, catching it and again just waiting for
> the next message make it more robust?
>
> Regards,
> Rahul.
>