Skip to content

Commit

Permalink
Docs - close() versus stop() in MessageConsumer (#1271)
Browse files Browse the repository at this point in the history
* Docs - close() versus stop() in MessageConsumer

* Update MessageConsumer.java
  • Loading branch information
roeschter authored Jan 16, 2025
1 parent 366ae9f commit a48f61e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/nats/client/JetStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
* </pre>
*
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/nats/client/MessageConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a48f61e

Please sign in to comment.