Skip to content
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

[FIXED] Do not overwrite ordered consumer deliver policy if start time is set #1742

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions jetstream/ordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,18 +631,16 @@ func (c *orderedConsumer) getConsumerConfig() *ConsumerConfig {
c.cfg.DeliverPolicy == DeliverAllPolicy {

cfg.OptStartSeq = 0
} else if c.cfg.DeliverPolicy == DeliverByStartTimePolicy {
cfg.OptStartSeq = 0
cfg.OptStartTime = c.cfg.OptStartTime
} else {
cfg.OptStartSeq = c.cfg.OptStartSeq
}

if cfg.DeliverPolicy == DeliverLastPerSubjectPolicy && len(c.cfg.FilterSubjects) == 0 {
cfg.FilterSubjects = []string{">"}
}
if c.cfg.OptStartTime != nil {
cfg.OptStartSeq = 0
cfg.DeliverPolicy = DeliverByStartTimePolicy
cfg.OptStartTime = c.cfg.OptStartTime
}

return cfg
}
Expand Down
50 changes: 50 additions & 0 deletions jetstream/test/ordered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,56 @@ func TestOrderedConsumerConfig(t *testing.T) {
HeadersOnly: true,
},
},
{
name: "both start seq and time set, deliver policy start seq",
config: jetstream.OrderedConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
DeliverPolicy: jetstream.DeliverByStartSequencePolicy,
OptStartSeq: 10,
OptStartTime: &time.Time{},
ReplayPolicy: jetstream.ReplayOriginalPolicy,
InactiveThreshold: 10 * time.Second,
HeadersOnly: true,
},
expected: jetstream.ConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
OptStartSeq: 10,
OptStartTime: nil,
DeliverPolicy: jetstream.DeliverByStartSequencePolicy,
AckPolicy: jetstream.AckNonePolicy,
MaxDeliver: -1,
MaxWaiting: 512,
InactiveThreshold: 10 * time.Second,
Replicas: 1,
MemoryStorage: true,
HeadersOnly: true,
},
},
{
name: "both start seq and time set, deliver policy start time",
config: jetstream.OrderedConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
DeliverPolicy: jetstream.DeliverByStartTimePolicy,
OptStartSeq: 10,
OptStartTime: &time.Time{},
ReplayPolicy: jetstream.ReplayOriginalPolicy,
InactiveThreshold: 10 * time.Second,
HeadersOnly: true,
},
expected: jetstream.ConsumerConfig{
FilterSubjects: []string{"foo.a", "foo.b"},
OptStartSeq: 0,
OptStartTime: &time.Time{},
DeliverPolicy: jetstream.DeliverByStartTimePolicy,
AckPolicy: jetstream.AckNonePolicy,
MaxDeliver: -1,
MaxWaiting: 512,
InactiveThreshold: 10 * time.Second,
Replicas: 1,
MemoryStorage: true,
HeadersOnly: true,
},
},
}

for _, test := range tests {
Expand Down