Skip to content

Commit

Permalink
fix(examples): sync exactly_once and consumergroup
Browse files Browse the repository at this point in the history
- ensure both examples handle sarama.ErrClosedConsumerGroup in the
  Consume for { ... } loop and ignore that error as it means the user
  has closed the ConsumerGroup directly via Close().
- ensure exactly_once handles the Messages() channel being closed with
  an ok check.
- copy assignment strategy optional flag from consumergroup into
  exactly_once sample
- bump the go.mod of both to specify 1.40.1 by default (although we
  still replace to ../.. anyway)

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>
  • Loading branch information
dnwe committed Aug 21, 2023
1 parent 913b18f commit d4dc7bc
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 946 deletions.
2 changes: 1 addition & 1 deletion examples/consumergroup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module github.com/IBM/sarama/examples/consumer

go 1.16

require github.com/IBM/sarama v1.34.1
require github.com/IBM/sarama v1.40.1

replace github.com/IBM/sarama => ../../
501 changes: 20 additions & 481 deletions examples/consumergroup/go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/consumergroup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
// SIGUSR1 toggle the pause/resume consumption
import (
"context"
"errors"
"flag"
"log"
"os"
Expand Down Expand Up @@ -106,6 +107,9 @@ func main() {
// server-side rebalance happens, the consumer session will need to be
// recreated to get the new claims
if err := client.Consume(ctx, strings.Split(topics, ","), &consumer); err != nil {
if errors.Is(err, sarama.ErrClosedConsumerGroup) {
return
}
log.Panicf("Error from consumer: %v", err)
}
// check if context was cancelled, signaling that the consumer should stop
Expand Down
2 changes: 1 addition & 1 deletion examples/exactly_once/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module github.com/IBM/sarama/examples/exactly_once

go 1.16

require github.com/IBM/sarama v1.34.1
require github.com/IBM/sarama v1.40.1

replace github.com/IBM/sarama => ../../
Loading

0 comments on commit d4dc7bc

Please sign in to comment.