-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make StreamListener read batch messages at once #3138
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
package org.springframework.data.redis.stream; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CountDownLatch; | ||
|
@@ -147,14 +148,14 @@ private List<ByteRecord> readRecords() { | |
} | ||
|
||
private void deserializeAndEmitRecords(List<ByteRecord> records) { | ||
List<V> messages = new ArrayList<>(); | ||
|
||
for (ByteRecord raw : records) { | ||
|
||
try { | ||
|
||
pollState.updateReadOffset(raw.getId().getValue()); | ||
V record = convertRecord(raw); | ||
listener.onMessage(record); | ||
messages.add(record); | ||
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. Batching introduces an error category of message loss if one of the messages causes an exception. In such a case, the read offset has been updated but the message was never delivered to a listener. 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. Thanks for the feedback. I will revise the PR based on your suggestions. |
||
} catch (RuntimeException ex) { | ||
|
||
if (cancelSubscriptionOnError.test(ex)) { | ||
|
@@ -166,8 +167,11 @@ private void deserializeAndEmitRecords(List<ByteRecord> records) { | |
} | ||
|
||
errorHandler.handleError(ex); | ||
return; | ||
} | ||
} | ||
|
||
listener.onMessage(messages); | ||
} | ||
|
||
private V convertRecord(ByteRecord record) { | ||
|
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.
That won't work as this is a breaking change.