Skip to content

Commit

Permalink
multi last for with batch
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf committed Nov 7, 2024
1 parent b7379bb commit e242724
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 262 deletions.
22 changes: 17 additions & 5 deletions src/main/java/io/nats/client/api/MessageBatchGetRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public static MessageBatchGetRequest batchBytes(String subject, int batch, int m
}

// multi for constructor
private MessageBatchGetRequest(List<String> subjects, long upToSequence, ZonedDateTime upToTime) {
private MessageBatchGetRequest(List<String> subjects, long upToSequence, ZonedDateTime upToTime, int batch) {
Validator.required(subjects, "Subjects");
batch = -1;
this.batch = batch;
nextBySubject = null;
this.maxBytes = -1;
this.minSequence = -1;
Expand All @@ -95,15 +95,27 @@ private MessageBatchGetRequest(List<String> subjects, long upToSequence, ZonedDa
}

public static MessageBatchGetRequest multiLastForSubjects(List<String> subjects) {
return new MessageBatchGetRequest(subjects, -1, null);
return new MessageBatchGetRequest(subjects, -1, null, -1);
}

public static MessageBatchGetRequest multiLastForSubjects(List<String> subjects, long upToSequence) {
return new MessageBatchGetRequest(subjects, upToSequence, null);
return new MessageBatchGetRequest(subjects, upToSequence, null, -1);
}

public static MessageBatchGetRequest multiLastForSubjects(List<String> subjects, ZonedDateTime upToTime) {
return new MessageBatchGetRequest(subjects, -1, upToTime);
return new MessageBatchGetRequest(subjects, -1, upToTime, -1);
}

public static MessageBatchGetRequest multiLastForSubjectsBatch(List<String> subjects, int batch) {
return new MessageBatchGetRequest(subjects, -1, null, batch);
}

public static MessageBatchGetRequest multiLastForSubjectsBatch(List<String> subjects, long upToSequence, int batch) {
return new MessageBatchGetRequest(subjects, upToSequence, null, batch);
}

public static MessageBatchGetRequest multiLastForSubjectsBatch(List<String> subjects, ZonedDateTime upToTime, int batch) {
return new MessageBatchGetRequest(subjects, -1, upToTime, batch);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/nats/client/api/MessageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private MessageInfo(Message msg, Status status, String streamName, boolean fromD
Headers _headers = null;
String _stream = null;
long _lastSeq = -1;
long _numPending = 0;
long _numPending = -1;
Status _status = null;

if (status != null) {
Expand Down Expand Up @@ -252,7 +252,7 @@ else if (hasError()) {
else {
JsonUtils.addField(sb, SEQ, seq);
JsonUtils.addField(sb, LAST_SEQ, lastSeq);
JsonUtils.addField(sb, NUM_PENDING, numPending);
JsonUtils.addFieldWhenGteMinusOne(sb, NUM_PENDING, numPending);
JsonUtils.addField(sb, STREAM, stream);
JsonUtils.addField(sb, SUBJECT, subject);
JsonUtils.addField(sb, TIME, time);
Expand Down
Loading

0 comments on commit e242724

Please sign in to comment.