Skip to content

Commit c0dcf12

Browse files
authored
Recommended (new) APIs and more example code (#1191)
1 parent 376ba3b commit c0dcf12

File tree

7 files changed

+61
-14
lines changed

7 files changed

+61
-14
lines changed

src/main/java/io/nats/client/Connection.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ enum Status {
571571

572572
/**
573573
* Get a stream context for a specific stream.
574+
*
575+
* <p><b>Recommended:</b> See {@link #getStreamContext(String, JetStreamOptions) getStreamContext(String, JetStreamOptions)}
574576
* @param streamName the stream for the context
575577
* @return a StreamContext instance.
576578
* @throws IOException covers various communication issues with the NATS
@@ -580,7 +582,23 @@ enum Status {
580582
StreamContext getStreamContext(String streamName) throws IOException, JetStreamApiException;
581583

582584
/**
583-
* Get a stream context for a specific stream.
585+
* Get a stream context for a specific stream
586+
* <p><b>Recommended:</b> {@link StreamContext StreamContext} and {@link ConsumerContext ConsumerContext} are the preferred way to interact with existing streams and consume from streams.
587+
* {@link JetStreamManagement JetStreamManagement} should be used to create streams and consumers. {@link ConsumerContext#consume ConsumerContext.consume()} supports both push and pull consumers transparently.
588+
*
589+
* <pre>
590+
* nc = Nats.connect();
591+
* StreamContext streamContext = nc.getStreamContext("my-stream");
592+
* ConsumerContext consumerContext = streamContext.getConsumerContext("my-consumer");
593+
* // Or directly:
594+
* // ConsumerContext consumerContext = nc.getConsumerContext("my-stream", "my-consumer");
595+
* consumerContext.consume(
596+
* msg -&gt; {
597+
* System.out.println(" Received " + msg.getSubject());
598+
* msg.ack();
599+
* });
600+
</pre>
601+
*
584602
* @param streamName the stream for the context
585603
* @param options JetStream options.
586604
* @return a StreamContext instance.
@@ -593,6 +611,9 @@ enum Status {
593611
/**
594612
* Get a consumer context for a specific named stream and specific named consumer.
595613
* Verifies that the stream and consumer exist.
614+
*
615+
* <p><b>Recommended:</b> See {@link #getStreamContext(String, JetStreamOptions) getStreamContext(String, JetStreamOptions)}
616+
*
596617
* @param streamName the name of the stream
597618
* @param consumerName the name of the consumer
598619
* @return a ConsumerContext object
@@ -605,6 +626,9 @@ enum Status {
605626
/**
606627
* Get a consumer context for a specific named stream and specific named consumer.
607628
* Verifies that the stream and consumer exist.
629+
*
630+
* <p><b>Recommended:</b> See {@link #getStreamContext(String, JetStreamOptions) getStreamContext(String, JetStreamOptions)}
631+
*
608632
* @param streamName the name of the stream
609633
* @param consumerName the name of the consumer
610634
* @param options JetStream options.

src/main/java/io/nats/client/api/MessageGetRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public static MessageGetRequest nextForSubject(long sequence, String subject) {
4444

4545
/**
4646
* @deprecated use static method forSequence with .serialize instead
47+
* @param sequence start sequence
48+
* @return rendered output
4749
*/
4850
@Deprecated
4951
public static byte[] seqBytes(long sequence) {
@@ -52,6 +54,8 @@ public static byte[] seqBytes(long sequence) {
5254

5355
/**
5456
* @deprecated use static method lastForSubject with .serialize instead
57+
* @param subject filter subject
58+
* @return rendered output
5559
*/
5660
@Deprecated
5761
public static byte[] lastBySubjectBytes(String subject) {
@@ -60,6 +64,8 @@ public static byte[] lastBySubjectBytes(String subject) {
6064

6165
/**
6266
* @deprecated use static method forSequence instead
67+
*
68+
* @param sequence start sequence number
6369
*/
6470
@Deprecated
6571
public MessageGetRequest(long sequence) {
@@ -68,6 +74,8 @@ public MessageGetRequest(long sequence) {
6874

6975
/**
7076
* @deprecated use static method lastForSubject instead
77+
*
78+
* @param lastBySubject filter subject
7179
*/
7280
@Deprecated
7381
public MessageGetRequest(String lastBySubject) {

src/main/java/io/nats/client/impl/DataPort.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ default void afterConstruct(Options options) {}
4545
/**
4646
* NOTE: the buffer will be modified if communicating over websockets and
4747
* the toWrite is greater than 1432.
48+
*
49+
* @param src output byte[]
50+
* @param toWrite number of bytes to write
51+
* @throws IOException any IO error on the underlaying connection
4852
*/
4953
void write(byte[] src, int toWrite) throws IOException;
5054

src/main/java/io/nats/client/impl/Headers.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ public Headers add(String key, String... values) {
106106
* If the key is not present, sets the specified values for the key.
107107
* null values are ignored. If all values are null, the key is not added or updated.
108108
*
109-
* @param key the key
110-
* @return the Headers object
109+
* @param key the entry key
110+
* @param values a list of values to the entry
111+
* @return the Header object
111112
* @throws IllegalArgumentException if the key is null or empty or contains invalid characters
112113
* -or- if any value contains invalid characters
113114
*/
@@ -262,16 +263,16 @@ private void _remove(String key) {
262263
/**
263264
* Returns the number of keys (case-sensitive) in the header.
264265
*
265-
* @return the number of keys
266+
* @return the number of header entries
266267
*/
267268
public int size() {
268269
return valuesMap.size();
269270
}
270271

271272
/**
272-
* Returns <tt>true</tt> if this map contains no keys.
273+
* Returns ture if map contains no keys.
273274
*
274-
* @return <tt>true</tt> if this map contains no keys
275+
* @return true if there are no headers
275276
*/
276277
public boolean isEmpty() {
277278
return valuesMap.isEmpty();
@@ -291,20 +292,20 @@ public void clear() {
291292
}
292293

293294
/**
294-
* Returns <tt>true</tt> if key (case-sensitive) is present (has values)
295+
* Returns true if key (case-sensitive) is present (has values)
295296
*
296297
* @param key key whose presence is to be tested
297-
* @return <tt>true</tt> if the key (case-sensitive) is present (has values)
298+
* @return true if the key (case-sensitive) is present (has values)
298299
*/
299300
public boolean containsKey(String key) {
300301
return valuesMap.containsKey(key);
301302
}
302303

303304
/**
304-
* Returns <tt>true</tt> if key (case-insensitive) is present (has values)
305+
* Returns true if key (case-insensitive) is present (has values)
305306
*
306307
* @param key exact key whose presence is to be tested
307-
* @return <tt>true</tt> if the key (case-insensitive) is present (has values)
308+
* @return true if the key (case-insensitive) is present (has values)
308309
*/
309310
public boolean containsKeyIgnoreCase(String key) {
310311
for (String k : valuesMap.keySet()) {
@@ -341,6 +342,7 @@ public Set<String> keySetIgnoreCase() {
341342
* Returns a {@link List} view of the values for the specific (case-sensitive) key.
342343
* Will be {@code null} if the key is not found.
343344
*
345+
* @param key the key whose associated value is to be returned
344346
* @return a read-only list of the values for the case-sensitive key.
345347
*/
346348
public List<String> get(String key) {
@@ -351,7 +353,7 @@ public List<String> get(String key) {
351353
/**
352354
* Returns the first value for the specific (case-sensitive) key.
353355
* Will be {@code null} if the key is not found.
354-
*
356+
* @param key the key whose associated value is to be returned
355357
* @return the first value for the case-sensitive key.
356358
*/
357359
public String getFirst(String key) {
@@ -363,6 +365,7 @@ public String getFirst(String key) {
363365
* Returns the last value for the specific (case-sensitive) key.
364366
* Will be {@code null} if the key is not found.
365367
*
368+
* @param key the key whose associated value is to be returned
366369
* @return the last value for the case-sensitive key.
367370
*/
368371
public String getLast(String key) {
@@ -374,6 +377,7 @@ public String getLast(String key) {
374377
* Returns a {@link List} view of the values for the specific (case-insensitive) key.
375378
* Will be {@code null} if the key is not found.
376379
*
380+
* @param key the key whose associated value is to be returned
377381
* @return a read-only list of the values for the case-insensitive key.
378382
*/
379383
public List<String> getIgnoreCase(String key) {
@@ -447,7 +451,10 @@ public byte[] getSerialized() {
447451

448452
/**
449453
* @deprecated
450-
* Appends the serialized bytes to the builder.
454+
* Used for unit testing.
455+
* Appends the serialized bytes to the builder.
456+
*
457+
* @param bab the ByteArrayBuilder to append
451458
* @return the builder
452459
*/
453460
@Deprecated

src/main/java/io/nats/client/impl/NatsConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void incrementDroppedCount() {
112112

113113
/**
114114
* @return the number of messages dropped from this consumer, since the last
115-
* call to {@link @clearDroppedCount}.
115+
* call to {@link #clearDroppedCount}.
116116
*/
117117
public long getDroppedCount() {
118118
return this.droppedMessages.get();

src/main/java/io/nats/client/impl/NatsObjectStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public ObjectInfo addBucketLink(String objectName, ObjectStore toStore) throws I
397397
/**
398398
* {@inheritDoc}
399399
*
400-
* @return
400+
* @return returs the new status info of the object store
401401
*/
402402
@Override
403403
public ObjectStoreStatus seal() throws IOException, JetStreamApiException {

src/main/javadoc/overview.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<head></head>
1818
<body>
1919
Java API for the <a href="http://nats.io">NATs messaging system</a>.
20+
<p>The Java API is hosted on <a href="https://github.com/nats-io/nats.java">Github NATS Java API</a>. Before starting to code, please check the <a href="https://github.com/nats-io/nats.java/blob/main/README.md"><b>README</b></a> for updates, hints and best practices.
21+
<p>Examples are collected in <a href="https://github.com/nats-io/nats.java/tree/main/src/examples/java/io/nats/examples">NATS Client API examples</a> and <a href="https://github.com/nats-io/java-nats-examples">NATS Java examples</a>
22+
<p>For more examples, including for other programming languages, see <a href="https://natsbyexample.com/">NATS By Example</a>, which is also hosted on <a href="https://github.com/nats-io/java-nats-examples">Github - NATS By Example</a> and open to contribution.
23+
2024
<p><img src="large-logo.png" alt="nats logo"></p>
2125

2226
<p>NATS Server is a simple, high performance open source messaging system for cloud native applications, IoT messaging, and microservices architectures.

0 commit comments

Comments
 (0)