Warning, though. `closed` is volatile. That shouldn't be too much of a
problem, but if something is odd, make a mental bookmark.  Consumer and
KafkaConsumer should have a permanent isClosed() method. It sure would be
handy.

I'll put it as an issue.



On Mon, May 29, 2023 at 8:47 PM Daniel Hinojosa <dhinoj...@evolutionnext.com>
wrote:

> As a stop-gap you can create something like the following.
>
> private static boolean isClosed(KafkaConsumer<String, String> consumer) {
> try {
> var consumerClass = consumer.getClass();
> Field field = consumerClass.getDeclaredField("closed");
> field.setAccessible(true);
> return (Boolean) field.get(consumer);
> } catch (NoSuchFieldException | IllegalAccessException e) {
> throw new RuntimeException(e);
> }
> }
>
>
>
>
>
>
> On Mon, May 29, 2023 at 2:11 AM Eric Li <e...@lexidus.com> wrote:
>
>> Hello everyone, my question is as the topic.
>>
>> In particular, when I have a Consumer object, I would like to see if
>>
>> https://github.com/apache/kafka/blob/2e1947d240607d53f071f61c875cfffc3fec47fe/clients/src/main/java/org/apache/kafka/clients/consumer/Consumer.java#L269
>> (kafka-clients-3.4.0
>> <https://github.com/apache/kafka/blob/2e1947d240607d53f071f61c875cfffc3fec47fe/clients/src/main/java/org/apache/kafka/clients/consumer/Consumer.java#L269(kafka-clients-3.4.0>)
>> has been called. Is it possible?
>>
>

Reply via email to