Skip to content

Commit

Permalink
Fix consumer subject filters
Browse files Browse the repository at this point in the history
The `FilterStreamBySubject` was appending subjects instead of setting
the passed value.
Additionally, it was not resetting the other filter subject field. That
could cause errors, as server denies consumer API calls with both
FilterSubject` and `FilterSubjects` set.`

Signed-off-by: Tomasz Pietrek <[email protected]>
  • Loading branch information
Jarema authored and ripienaar committed Mar 11, 2024
1 parent 2665d2c commit 5425bfe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions consumers.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,14 @@ func MaxDeliveryAttempts(n int) ConsumerOption {
func FilterStreamBySubject(s ...string) ConsumerOption {
return func(o *api.ConsumerConfig) error {
if len(s) == 1 {
// If there is only one filter, reset the multiple subjects filter.
o.FilterSubjects = nil
o.FilterSubject = s[0]
} else {
o.FilterSubjects = append(o.FilterSubjects, s...)
// If there are more subjects, reset the single subject filter.
o.FilterSubject = ""
o.FilterSubjects = s
}

return nil
}
}
Expand Down

0 comments on commit 5425bfe

Please sign in to comment.