You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/io/nats/client/JetStream.java
+111-2Lines changed: 111 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,101 @@
13
13
14
14
packageio.nats.client;
15
15
16
+
importio.nats.client.api.ConsumerConfiguration;
16
17
importio.nats.client.api.PublishAck;
18
+
importio.nats.client.api.StorageType;
19
+
importio.nats.client.api.StreamConfiguration;
17
20
importio.nats.client.impl.Headers;
18
21
19
22
importjava.io.IOException;
20
23
importjava.time.Duration;
21
24
importjava.util.concurrent.CompletableFuture;
22
25
23
26
/**
24
-
* JetStream context for creation and access to streams and consumers in NATS.
27
+
* JetStream context for access to streams and consumers in NATS.
28
+
*
29
+
* <h3>Basic usage</h3>
30
+
*
31
+
* <p>{@link #publish(String, byte[]) JetStream.Publish} will send a message on the specified subject, waiting for acknowledgement.
32
+
* A <b>503 No responders</b> error will be received if no stream is listening on said subject.
33
+
*
34
+
* <p>{@link #publishAsync(String, byte[]) PublishAsync} will not wait for acknowledgement but return a {@link CompletableFuture CompletableFuture},
35
+
* which can be checked for acknowledgement at a later point.
36
+
*
37
+
* <p> Use {@link #getStreamContext(String ) getStreamContext(String)} to access a simplified API for <b>consuming/subscribing</b> messages from Jetstream.
38
+
* It is <b>recommened</b> to manage consumers explicitely through {@link StreamContext StreamContext} or {@link JetStreamManagement JetStreamManagement}
39
+
*
40
+
* <p>{@link #subscribe(String)} is a convenience method for implicitly creating a consumer on a stream and receiving messages. This method should be used for ephemeral (not durable) conusmers.
41
+
* It can create a named durable consumers though Options, but we prefer to avoid creating durable consumers implictly.
42
+
* It is <b>recommened</b> to manage consumers explicitely through {@link StreamContext StreamContext} or {@link JetStreamManagement JetStreamManagement}
43
+
*
44
+
* {@link ConsumerContext ConsumerContext} based subscription.
45
+
*
46
+
* <h3>Recommended usage for creating streams, consumers, publish and listen on a stream</h3>
* <h3>Recommended usage of asynchronous publishing</h3>
84
+
*
85
+
* Jetstream messages can be published asynchronously, returning a CompletableFuture.
86
+
* Note that you need to check the Future eventually otherwise the delivery guarantee is the same a regular {@link Connection#publish(String, byte[]) Connection.Publish}
87
+
*
88
+
* <p>We are publishing a batch of 100 messages and check for completion afterwards.
89
+
*
90
+
* <pre>
91
+
* int COUNT = 100;
92
+
* java.util.concurrent.CompletableFuture<?>[] acks = new java.util.concurrent.CompletableFuture<?>[COUNT];
* Create an asynchronous subscription to the specified subject in the mode of pull, with additional options
547
+
* Create an asynchronous subscription to the specified subject in the mode of pull, with additional options.
548
+
*
462
549
* @param subscribeSubject The subject to subscribe to
463
550
* Can be null or empty when the options have a ConsumerConfiguration that supplies a filter subject.
464
551
* @param dispatcher The dispatcher to handle this subscription
@@ -473,6 +560,25 @@ public interface JetStream {
473
560
474
561
/**
475
562
* Get a stream context for a specific named stream. Verifies that the stream exists.
563
+
*
564
+
* <p><b>Recommended usage:</b> {@link StreamContext StreamContext} and {@link ConsumerContext ConsumerContext} are the preferred way to interact with existing streams and consume from streams.
565
+
* {@link JetStreamManagement JetStreamManagement} should be used to create streams and consumers. {@link ConsumerContext#consume ConsumerContext.consume()} supports both push and pull consumers transparently.
0 commit comments