From a48f61eaee0dff4564100255942e4d393c008c2c Mon Sep 17 00:00:00 2001 From: roeschter Date: Thu, 16 Jan 2025 17:50:05 +0100 Subject: [PATCH] Docs - close() versus stop() in MessageConsumer (#1271) * Docs - close() versus stop() in MessageConsumer * Update MessageConsumer.java --- src/main/java/io/nats/client/JetStream.java | 5 +++-- src/main/java/io/nats/client/MessageConsumer.java | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/nats/client/JetStream.java b/src/main/java/io/nats/client/JetStream.java index 30738cd1b..9c576bbad 100644 --- a/src/main/java/io/nats/client/JetStream.java +++ b/src/main/java/io/nats/client/JetStream.java @@ -73,9 +73,10 @@ * * js.publish("foo.joe", "Hello World".getBytes()); * - * //Wait a moment, then stop the MessageConsumer + * //Wait a moment, then stop and close the MessageConsumer * Thread.sleep(3000); - * mc.stop(); + * mc.stop(); //Stops pull requests + * mc.close(); //Unsubcribes * * * diff --git a/src/main/java/io/nats/client/MessageConsumer.java b/src/main/java/io/nats/client/MessageConsumer.java index 1ef6bec42..b4a1b305d 100644 --- a/src/main/java/io/nats/client/MessageConsumer.java +++ b/src/main/java/io/nats/client/MessageConsumer.java @@ -46,11 +46,17 @@ public interface MessageConsumer extends AutoCloseable { ConsumerInfo getCachedConsumerInfo(); /** - * Stop the MessageConsumer from asking for any more messages from the server. + * Use {@link close()} to unsubscribe. Stop will not unsubcribe or clean up resources. * The consumer will finish all pull request already in progress, but will not start any new ones. */ void stop(); + /** + * Unsubscribe the underlying subject. Close will be lenient. In flight and buffered messages may still be delivered. + */ + @Override + void close() throws Exception; + /** * Stopped indicates whether consuming has been stopped. Can be stopped without being finished. * @return the stopped flag