GitHub user BewareMyPower added a comment to the discussion: Why don't
org.apache.pulsar.client.api.Producer and org.apache.pulsar.client.api.Consumer
provide an isClose method?
> I cannot listen for their close events.
Since the close state can only be changed by calling `closeAsync` in your
client side, you can remember the state by yourself.
If you want to mark it as closed when the state is `Closing` or `Closed` you
can just write:
```java
producer.closeAsync();
closed = true;
```
If you want to mark it as closed only when the state is `Closed` you can write:
```java
producer.closeAsync().whenComplete((_, e) -> {
if (e != null) {
closed.set(true); // closed is an AtomicInteger
}
});
```
If you even want to treat the `Failed` state as closed, you can write:
```java
producer.closeAsync().whenComplete((_, e) -> {
closed.set(true); // closed is an AtomicInteger
});
```
The current `closeAsync` API is flexible enough.
So The `PulsarClient#isClosed` does not make sense to me as well. @tisonkun
GitHub link:
https://github.com/apache/pulsar/discussions/20510#discussioncomment-6118854
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]