-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Direct Get by start time #1226
Changes from all commits
2a425f9
368921d
c1a0a95
6b7406a
8de8df8
de4c0c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
import io.nats.client.support.JsonSerializable; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import static io.nats.client.support.ApiConstants.*; | ||
import static io.nats.client.support.JsonUtils.*; | ||
|
||
|
@@ -25,21 +27,30 @@ public class MessageGetRequest implements JsonSerializable { | |
private final long sequence; | ||
private final String lastBySubject; | ||
private final String nextBySubject; | ||
private final ZonedDateTime startTime; | ||
|
||
public static MessageGetRequest forSequence(long sequence) { | ||
return new MessageGetRequest(sequence, null, null); | ||
return new MessageGetRequest(sequence, null, null, null); | ||
} | ||
|
||
public static MessageGetRequest lastForSubject(String subject) { | ||
return new MessageGetRequest(-1, subject, null); | ||
return new MessageGetRequest(-1, subject, null, null); | ||
} | ||
|
||
public static MessageGetRequest firstForSubject(String subject) { | ||
return new MessageGetRequest(-1, null, subject); | ||
return new MessageGetRequest(-1, null, subject, null); | ||
} | ||
|
||
public static MessageGetRequest firstForStartTime(ZonedDateTime startTime) { | ||
return new MessageGetRequest(-1, null, null, startTime); | ||
} | ||
|
||
public static MessageGetRequest firstForStartTimeAndSubject(ZonedDateTime startTime, String subject) { | ||
return new MessageGetRequest(-1, null, subject, startTime); | ||
} | ||
|
||
public static MessageGetRequest nextForSubject(long sequence, String subject) { | ||
return new MessageGetRequest(sequence, null, subject); | ||
return new MessageGetRequest(sequence, null, subject, null); | ||
} | ||
|
||
/** | ||
|
@@ -69,7 +80,7 @@ public static byte[] lastBySubjectBytes(String subject) { | |
*/ | ||
@Deprecated | ||
public MessageGetRequest(long sequence) { | ||
this(sequence, null, null); | ||
this(sequence, null, null, null); | ||
} | ||
|
||
/** | ||
|
@@ -79,13 +90,14 @@ public MessageGetRequest(long sequence) { | |
*/ | ||
@Deprecated | ||
public MessageGetRequest(String lastBySubject) { | ||
this(-1, lastBySubject, null); | ||
this(-1, lastBySubject, null, null); | ||
} | ||
|
||
private MessageGetRequest(long sequence, String lastBySubject, String nextBySubject) { | ||
private MessageGetRequest(long sequence, String lastBySubject, String nextBySubject, ZonedDateTime startTime) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should add a builder to this class, especially if we are going to add a generic get message api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the builder 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
this.sequence = sequence; | ||
this.lastBySubject = lastBySubject; | ||
this.nextBySubject = nextBySubject; | ||
this.startTime = startTime; | ||
} | ||
|
||
public long getSequence() { | ||
|
@@ -118,6 +130,7 @@ public String toJson() { | |
addField(sb, SEQ, sequence); | ||
addField(sb, LAST_BY_SUBJECT, lastBySubject); | ||
addField(sb, NEXT_BY_SUBJECT, nextBySubject); | ||
addField(sb, START_TIME, startTime); | ||
return endJson(sb).toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1293,6 +1293,8 @@ private void validateGetMessage(JetStreamManagement jsm, TestingStreamContainer | |
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, 0, tsc.subject(1)), beforeCreated); | ||
assertMessageInfo(tsc, 0, 1, jsm.getFirstMessage(tsc.stream, tsc.subject(0)), beforeCreated); | ||
assertMessageInfo(tsc, 1, 2, jsm.getFirstMessage(tsc.stream, tsc.subject(1)), beforeCreated); | ||
assertMessageInfo(tsc, 0, 1, jsm.getFirstMessage(tsc.stream, beforeCreated), beforeCreated); | ||
assertMessageInfo(tsc, 1, 2, jsm.getFirstMessage(tsc.stream, beforeCreated, tsc.subject(1)), beforeCreated); | ||
|
||
assertMessageInfo(tsc, 0, 1, jsm.getNextMessage(tsc.stream, 1, tsc.subject(0)), beforeCreated); | ||
assertMessageInfo(tsc, 1, 2, jsm.getNextMessage(tsc.stream, 1, tsc.subject(1)), beforeCreated); | ||
|
@@ -1305,6 +1307,7 @@ private void validateGetMessage(JetStreamManagement jsm, TestingStreamContainer | |
|
||
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, -1))); | ||
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 0))); | ||
assertStatus(10003, assertThrows(JetStreamApiException.class, () -> jsm.getFirstMessage(tsc.stream, DEFAULT_TIME))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, is it correct that this fails because the start time is before the very first message in the stream? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't fail because of the start time being before the first message. |
||
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getMessage(tsc.stream, 9))); | ||
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getLastMessage(tsc.stream, "not-a-subject"))); | ||
assertStatus(10037, assertThrows(JetStreamApiException.class, () -> jsm.getFirstMessage(tsc.stream, "not-a-subject"))); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there ever a case when we will want first message by subject and start time? It's probably fine to have this since it seems like a common behavior, but I think it's time to expose something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, in combination with the new builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some discussion offline removed the builder again, as the only combinations that needed to be added were:
getFirstMessage(streamName, startTime)
getFirstMessage(streamName, startTime, subject)
And then we don't need extra validation in the builder for valid combinations.