Skip to content

Commit

Permalink
Deprecate LastConsumed method (#324)
Browse files Browse the repository at this point in the history
The method does not indicate the last message consumed of the stream but the last stored offset.
The method was added to help the user, but it created confusion.
env.QueryOffset(consumerName, streamName) should be used

Signed-off-by: Gabriele Santomaggio <[email protected]>
  • Loading branch information
Gsantomaggio authored Jun 25, 2024
1 parent 85d1327 commit 0324edc
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pkg/stream/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,12 @@ func (consumer *Consumer) QueryOffset() (int64, error) {
SetOffset constants
*/
const (
typeFirst = int16(1)
typeLast = int16(2)
typeNext = int16(3)
typeOffset = int16(4)
typeTimestamp = int16(5)
typeFirst = int16(1)
typeLast = int16(2)
typeNext = int16(3)
typeOffset = int16(4)
typeTimestamp = int16(5)
// Deprecated: see LastConsumed()
typeLastConsumed = int16(6)
)

Expand Down Expand Up @@ -476,13 +477,25 @@ func (o OffsetSpecification) isOffset() bool {
return o.typeOfs == typeOffset || o.typeOfs == typeLastConsumed
}

// Deprecated: see LastConsumed()
func (o OffsetSpecification) isLastConsumed() bool {
return o.typeOfs == typeLastConsumed
}
func (o OffsetSpecification) isTimestamp() bool {
return o.typeOfs == typeTimestamp
}

// Deprecated: The method name may be misleading.
// The method does not indicate the last message consumed of the stream but the last stored offset.
// The method was added to help the user, but it created confusion.
// Use `QueryOffset` instead.:
//
// offset, err := env.QueryOffset(consumerName, streamName)
// // check the error
// ....
// SetOffset(stream.OffsetSpecification{}.Offset(offset)).
//
// So in this way it possible to start from the last offset stored and customize the behavior
func (o OffsetSpecification) LastConsumed() OffsetSpecification {
o.typeOfs = typeLastConsumed
o.offset = -1
Expand Down

0 comments on commit 0324edc

Please sign in to comment.