Skip to content

Commit f336bae

Browse files
authored
Revert mistake removal of getFirstMessage (#1248)
1 parent 10db91d commit f336bae

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins {
1313
id 'signing'
1414
}
1515

16-
def jarVersion = "2.20.3"
16+
def jarVersion = "2.20.4"
1717

1818
def isRelease = System.getenv("BUILD_EVENT") == "release"
1919
def brn = System.getenv("BRANCH_REF_NAME")

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ 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+
274285
/**
275286
* Get MessageInfo for the message of the message sequence
276287
* is equal to or greater the requested sequence for the subject.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ 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+
166176
/**
167177
* Get MessageInfo for the message of the message sequence
168178
* is equal to or greater the requested sequence for the subject.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ 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+
284292
/**
285293
* {@inheritDoc}
286294
*/

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ 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+
150158
/**
151159
* {@inheritDoc}
152160
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,8 @@ 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);
12941296

12951297
assertMessageInfo(tsc, 0, 1, jsm.getNextMessage(tsc.stream, 1, tsc.subject(0)), beforeCreated);
12961298
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, 1, tsc.subject(1)), beforeCreated);
@@ -1305,6 +1307,7 @@ private void validateGetMessage(JetStreamManagement jsm, TestingStreamContainer
13051307
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 0)));
13061308
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 9)));
13071309
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getLastMessage(tsc.stream, "not-a-subject")));
1310+
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getFirstMessage(tsc.stream, "not-a-subject")));
13081311
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getNextMessage(tsc.stream, 9, tsc.subject(0))));
13091312
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getNextMessage(tsc.stream, 1, "not-a-subject")));
13101313
}

0 commit comments

Comments
 (0)