Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.data.redis.core.StreamOperations;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ErrorHandler;
import org.springframework.util.ObjectUtils;

Expand All @@ -50,6 +51,7 @@
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Edsuns
* @since 2.2
*/
class DefaultStreamMessageListenerContainer<K, V extends Record<K, ?>> implements StreamMessageListenerContainer<K, V> {
Expand Down Expand Up @@ -229,8 +231,18 @@ private Function<ReadOffset, List<ByteRecord>> getReadFunction(StreamReadRequest
: this.readOptions;
Consumer consumer = consumerStreamRequest.getConsumer();

return (offset) -> template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands()
.xReadGroup(consumer, readOptions, StreamOffset.create(rawKey, offset)));
return (offset) -> {
List<ByteRecord> records = template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands()
.xReadGroup(consumer, readOptions, StreamOffset.create(rawKey, offset)));
if (CollectionUtils.isEmpty(records) && !ReadOffset.lastConsumed().equals(offset)) {
// see https://redis.io/docs/latest/commands/xreadgroup/
// if ID in XREADGROUP command is other than >, new messages won't be read
// so reads new messages here
return template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands()
.xReadGroup(consumer, readOptions, StreamOffset.create(rawKey, ReadOffset.lastConsumed())));
}
return records;
};
}

return (offset) -> template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands()
Expand Down