Skip to content

Commit 10db91d

Browse files
authoredNov 1, 2024
getFirstMessage is a 2.11 feature (#1246)
1 parent 1ceea55 commit 10db91d

8 files changed

+6
-103
lines changed
 

‎src/main/java/io/nats/client/BaseConsumeOptions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public class BaseConsumeOptions implements JsonSerializable {
4949
protected BaseConsumeOptions(Builder b) {
5050
bytes = b.bytes;
5151
if (bytes > 0) {
52-
messages = b.messages == -1 ? DEFAULT_MESSAGE_COUNT_WHEN_BYTES : b.messages;
52+
messages = b.messages < 0 ? DEFAULT_MESSAGE_COUNT_WHEN_BYTES : b.messages;
5353
}
5454
else {
55-
messages = b.messages == -1 ? DEFAULT_MESSAGE_COUNT : b.messages;
55+
messages = b.messages < 0 ? DEFAULT_MESSAGE_COUNT : b.messages;
5656
}
5757

5858
// validation handled in builder

‎src/main/java/io/nats/client/ConnectionListener.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* listener is configured in the {@link Options Options} at creation time.
1919
*/
2020
public interface ConnectionListener {
21-
public enum Events {
21+
enum Events {
2222
/** The connection has successfully completed the handshake with the nats-server. */
2323
CONNECTED(true, "opened"),
2424
/** The connection is permanently closed, either by manual action or failed reconnects. */
@@ -29,7 +29,7 @@ public enum Events {
2929
RECONNECTED(true, "reconnected"),
3030
/** The connection was reconnected and the server has been notified of all subscriptions. */
3131
RESUBSCRIBED(false, "subscriptions re-established"),
32-
/** The connection was told about new servers from, from the current server. */
32+
/** The connection was made aware of new servers from the current server connection. */
3333
DISCOVERED_SERVERS(false, "discovered servers"),
3434
/** Server Sent a lame duck mode. */
3535
LAME_DUCK(false, "lame duck mode");
@@ -77,5 +77,5 @@ public String toString() {
7777
* @param conn the connection associated with the error
7878
* @param type the type of event that has occurred
7979
*/
80-
public void connectionEvent(Connection conn, Events type);
81-
}
80+
void connectionEvent(Connection conn, Events type);
81+
}

‎src/main/java/io/nats/client/JetStreamManagement.java

-40
Original file line numberDiff line numberDiff line change
@@ -271,46 +271,6 @@ public interface JetStreamManagement {
271271
*/
272272
MessageInfo getLastMessage(String streamName, String subject) throws IOException, JetStreamApiException;
273273

274-
/**
275-
* Get MessageInfo for the first message of the subject.
276-
* @param streamName the name of the stream.
277-
* @param subject the subject to get the first message for.
278-
* @return The MessageInfo
279-
* @throws IOException covers various communication issues with the NATS
280-
* server such as timeout or interruption
281-
* @throws JetStreamApiException the request had an error related to the data
282-
*/
283-
MessageInfo getFirstMessage(String streamName, String subject) throws IOException, JetStreamApiException;
284-
285-
/**
286-
* Get MessageInfo for the first message created at or after the start time.
287-
* <p>
288-
* This API is currently EXPERIMENTAL and is subject to change.
289-
*
290-
* @param streamName the name of the stream.
291-
* @param startTime the start time to get the first message for.
292-
* @return The MessageInfo
293-
* @throws IOException covers various communication issues with the NATS
294-
* server such as timeout or interruption
295-
* @throws JetStreamApiException the request had an error related to the data
296-
*/
297-
MessageInfo getFirstMessage(String streamName, ZonedDateTime startTime) throws IOException, JetStreamApiException;
298-
299-
/**
300-
* Get MessageInfo for the first message created at or after the start time matching the subject.
301-
* <p>
302-
* This API is currently EXPERIMENTAL and is subject to change.
303-
*
304-
* @param streamName the name of the stream.
305-
* @param startTime the start time to get the first message for.
306-
* @param subject the subject to get the first message for.
307-
* @return The MessageInfo
308-
* @throws IOException covers various communication issues with the NATS
309-
* server such as timeout or interruption
310-
* @throws JetStreamApiException the request had an error related to the data
311-
*/
312-
MessageInfo getFirstMessage(String streamName, ZonedDateTime startTime, String subject) throws IOException, JetStreamApiException;
313-
314274
/**
315275
* Get MessageInfo for the message of the message sequence
316276
* is equal to or greater the requested sequence for the subject.

‎src/main/java/io/nats/client/StreamContext.java

-10
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,6 @@ public interface StreamContext {
163163
*/
164164
MessageInfo getLastMessage(String subject) throws IOException, JetStreamApiException;
165165

166-
/**
167-
* Get MessageInfo for the first message of the subject.
168-
* @param subject the subject to get the first message for.
169-
* @return The MessageInfo
170-
* @throws IOException covers various communication issues with the NATS
171-
* server such as timeout or interruption
172-
* @throws JetStreamApiException the request had an error related to the data
173-
*/
174-
MessageInfo getFirstMessage(String subject) throws IOException, JetStreamApiException;
175-
176166
/**
177167
* Get MessageInfo for the message of the message sequence
178168
* is equal to or greater the requested sequence for the subject.

‎src/main/java/io/nats/client/impl/NatsJetStreamManagement.java

-24
Original file line numberDiff line numberDiff line change
@@ -281,30 +281,6 @@ public MessageInfo getLastMessage(String streamName, String subject) throws IOEx
281281
return _getMessage(streamName, MessageGetRequest.lastForSubject(subject));
282282
}
283283

284-
/**
285-
* {@inheritDoc}
286-
*/
287-
@Override
288-
public MessageInfo getFirstMessage(String streamName, String subject) throws IOException, JetStreamApiException {
289-
return _getMessage(streamName, MessageGetRequest.firstForSubject(subject));
290-
}
291-
292-
/**
293-
* {@inheritDoc}
294-
*/
295-
@Override
296-
public MessageInfo getFirstMessage(String streamName, ZonedDateTime startTime) throws IOException, JetStreamApiException {
297-
return _getMessage(streamName, MessageGetRequest.firstForStartTime(startTime));
298-
}
299-
300-
/**
301-
* {@inheritDoc}
302-
*/
303-
@Override
304-
public MessageInfo getFirstMessage(String streamName, ZonedDateTime startTime, String subject) throws IOException, JetStreamApiException {
305-
return _getMessage(streamName, MessageGetRequest.firstForStartTimeAndSubject(startTime, subject));
306-
}
307-
308284
/**
309285
* {@inheritDoc}
310286
*/

‎src/main/java/io/nats/client/impl/NatsStreamContext.java

-8
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ public MessageInfo getLastMessage(String subject) throws IOException, JetStreamA
147147
return jsm.getLastMessage(streamName, subject);
148148
}
149149

150-
/**
151-
* {@inheritDoc}
152-
*/
153-
@Override
154-
public MessageInfo getFirstMessage(String subject) throws IOException, JetStreamApiException {
155-
return jsm.getFirstMessage(streamName, subject);
156-
}
157-
158150
/**
159151
* {@inheritDoc}
160152
*/

‎src/test/java/io/nats/client/impl/JetStreamManagementTests.java

-6
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,6 @@ private void validateGetMessage(JetStreamManagement jsm, TestingStreamContainer
12911291
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, -1, tsc.subject(1)), beforeCreated);
12921292
assertMessageInfo(tsc, 0, 1, jsm.getNextMessage(tsc.stream, 0, tsc.subject(0)), beforeCreated);
12931293
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, 0, tsc.subject(1)), beforeCreated);
1294-
assertMessageInfo(tsc, 0, 1, jsm.getFirstMessage(tsc.stream, tsc.subject(0)), beforeCreated);
1295-
assertMessageInfo(tsc, 1, 2, jsm.getFirstMessage(tsc.stream, tsc.subject(1)), beforeCreated);
1296-
assertMessageInfo(tsc, 0, 1, jsm.getFirstMessage(tsc.stream, beforeCreated), beforeCreated);
1297-
assertMessageInfo(tsc, 1, 2, jsm.getFirstMessage(tsc.stream, beforeCreated, tsc.subject(1)), beforeCreated);
12981294

12991295
assertMessageInfo(tsc, 0, 1, jsm.getNextMessage(tsc.stream, 1, tsc.subject(0)), beforeCreated);
13001296
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, 1, tsc.subject(1)), beforeCreated);
@@ -1307,10 +1303,8 @@ private void validateGetMessage(JetStreamManagement jsm, TestingStreamContainer
13071303

13081304
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, -1)));
13091305
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 0)));
1310-
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getFirstMessage(tsc.stream, DEFAULT_TIME)));
13111306
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 9)));
13121307
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getLastMessage(tsc.stream, "not-a-subject")));
1313-
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getFirstMessage(tsc.stream, "not-a-subject")));
13141308
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getNextMessage(tsc.stream, 9, tsc.subject(0))));
13151309
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getNextMessage(tsc.stream, 1, "not-a-subject")));
13161310
}

‎src/test/java/io/nats/client/impl/SimplificationTests.java

-9
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ private static void _testStreamContext(JetStream js, TestingStreamContainer tsc,
109109
MessageInfo mi = streamContext.getMessage(1);
110110
assertEquals(1, mi.getSeq());
111111

112-
mi = streamContext.getFirstMessage(tsc.subject());
113-
assertEquals(1, mi.getSeq());
114-
115112
mi = streamContext.getLastMessage(tsc.subject());
116113
assertEquals(6, mi.getSeq());
117114

@@ -123,12 +120,6 @@ private static void _testStreamContext(JetStream js, TestingStreamContainer tsc,
123120

124121
streamContext.purge(PurgeOptions.builder().sequence(5).build());
125122
assertThrows(JetStreamApiException.class, () -> streamContext.getMessage(1));
126-
127-
mi = streamContext.getFirstMessage(tsc.subject());
128-
assertEquals(5, mi.getSeq());
129-
130-
streamContext.purge();
131-
assertThrows(JetStreamApiException.class, () -> streamContext.getFirstMessage(tsc.subject()));
132123
}
133124

134125
static int FETCH_EPHEMERAL = 1;

0 commit comments

Comments
 (0)