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

kafkabp: Add NewConsumerWithConfigOverriders #639

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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
14 changes: 14 additions & 0 deletions kafkabp/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,25 @@ type consumer struct {
// topic. This implementation of Kafka consumer is suitable for use cases like
// deliver config/data through Kafka to services.
func NewConsumer(cfg ConsumerConfig) (Consumer, error) {
return NewConsumerWithConfigOverriders(cfg)
}

// SaramaConfigOverrider provides a way for users to override certain fields in
// *sarama.Config generated from ConsumerConfig.
type SaramaConfigOverrider func(*sarama.Config)

// NewConsumerWithConfigOverriders is provided as an escape hatch for use cases
// requiring specific sarama config not supported by ConsumerConfig.
func NewConsumerWithConfigOverriders(cfg ConsumerConfig, overriders ...SaramaConfigOverrider) (Consumer, error) {
sc, err := cfg.NewSaramaConfig()
if err != nil {
return nil, err
}

for _, override := range overriders {
override(sc)
}

switch {
default:
return newTopicConsumer(cfg, sc)
Expand Down