From 0324edc7ce2603df39ee8411ac9f95989df8423e Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Tue, 25 Jun 2024 14:56:13 +0200 Subject: [PATCH] Deprecate LastConsumed method (#324) 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 --- pkg/stream/consumer.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/stream/consumer.go b/pkg/stream/consumer.go index d8f1527e..f310f834 100644 --- a/pkg/stream/consumer.go +++ b/pkg/stream/consumer.go @@ -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) ) @@ -476,6 +477,7 @@ func (o OffsetSpecification) isOffset() bool { return o.typeOfs == typeOffset || o.typeOfs == typeLastConsumed } +// Deprecated: see LastConsumed() func (o OffsetSpecification) isLastConsumed() bool { return o.typeOfs == typeLastConsumed } @@ -483,6 +485,17 @@ 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