This version is still in development and is not considered stable yet. For the latest stable version, please use spring-cloud-stream 4.1.3! |
Resetting Offsets
When an application starts, the initial position in each assigned partition depends on two properties startOffset
and resetOffsets
.
If resetOffsets
is false
, normal Kafka consumer auto.offset.reset
semantics apply.
i.e. If there is no committed offset for a partition for the binding’s consumer group, the position is earliest
or latest
.
By default, bindings with an explicit group
use earliest
, and anonymous bindings (with no group
) use latest
.
These defaults can be overridden by setting the startOffset
binding property.
There will be no committed offset(s) the first time the binding is started with a particular group
.
The other condition where no committed offset exists is if the offset has been expired.
With modern brokers (since 2.1), and default broker properties, the offsets are expired 7 days after the last member leaves the group.
See the offsets.retention.minutes
broker property for more information.
When resetOffsets
is true
, the binder applies similar semantics to those that apply when there is no committed offset on the broker, as if this binding has never consumed from the topic; i.e. any current committed offset is ignored.
Following are two use cases when this might be used.
-
Consuming from a compacted topic containing key/value pairs. Set
resetOffsets
totrue
andstartOffset
toearliest
; the binding will perform aseekToBeginning
on all newly assigned partitions. -
Consuming from a topic containing events, where you are only interested in events that occur while this binding is running. Set
resetOffsets
totrue
andstartOffset
tolatest
; the binding will perform aseekToEnd
on all newly assigned partitions.
If a rebalance occurs after the initial assignment, the seeks will only be performed on any newly assigned partitions that were not assigned during the initial assignment. |
For more control over topic offsets, see rebalance listener; when a listener is provided, resetOffsets
should not be set to true
, otherwise, that will cause an error.