[ 
https://issues.apache.org/jira/browse/KAFKA-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14311699#comment-14311699
 ] 

Jay Kreps commented on KAFKA-1660:
----------------------------------

This is very similar to KAFKA-1659 and KAFKA-1934.

We should do the discussion on the new API as a KIP.

I think there are two possible APIs that could be added.

The first variant attempts to close the producer but will only wait for up to 
the given period of time. It returns whether the close succeeded or not.
{code}
  public boolean tryClose(long timeout, TimeUnit unit);
{code}
One challenge here is how to stop sends on other threads. The current 
implementation will actually throw an exception if you call send after you call 
close. But in this variant I guess the idea is that if tryClose fails you would 
want to have a non-closed producer instance so we would have to rethink that. 
I'm not sure actually how solvable that is.

The second variant always closes the producer and attempts to do this 
gracefully, waiting for all sends to complete, but if graceful sending doesn't 
work by the time the timeout expires it just shuts down the sender thread and 
exits:
{code}
  public void close(long timeout, TimeUnit unit);
{code}

I actually think the second case is more usable---I think in most cases what 
you want is to try to get rid of the messages you have for a good period of 
time but not block forever. I think users of the first api would generally not 
have any good recourse when tryClose failed and would just end up leaking the 
connections and i/o thread.

> Ability to call close() with a timeout on the Java Kafka Producer. 
> -------------------------------------------------------------------
>
>                 Key: KAFKA-1660
>                 URL: https://issues.apache.org/jira/browse/KAFKA-1660
>             Project: Kafka
>          Issue Type: Improvement
>          Components: clients, producer 
>    Affects Versions: 0.8.2
>            Reporter: Andrew Stein
>            Assignee: Jun Rao
>             Fix For: 0.8.3
>
>         Attachments: KAFKA-1660.patch
>
>
> I would like the ability to call {{close}} with a timeout on the Java 
> Client's KafkaProducer.
> h6. Workaround
> Currently, it is possible to ensure that {{close}} will return quickly by 
> first doing a {{future.get(timeout)}} on the last future produced on each 
> partition, but this means that the user has to define the partitions up front 
> at the time of {{send}} and track the returned {{future}}'s



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to