Skip to content

Commit

Permalink
Merge pull request #83 from igmagollo/feat/enable-rmq-prefetch
Browse files Browse the repository at this point in the history
feat: add RABBIT_PREFETCH_COUNT to configure channel prefetch count option
  • Loading branch information
TheRafaBonin authored Feb 2, 2024
2 parents d39dc28 + 0561078 commit 14922b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions internal/events/rabbitmq/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
URL string
ConsumerName string
ConsumerConcurrency int
PrefetchCount int

MaxRetries int
InitialInterval time.Duration
Expand Down Expand Up @@ -81,6 +82,18 @@ func LoadConfig(log *zerolog.Logger) Config {
log.Info().Msgf("RABBIT_CONSUMER_CONCURRENCY is not set, defaulting to %d", c.ConsumerConcurrency)
}

prefetchCount := os.Getenv("RABBIT_PREFETCH_COUNT")
if prefetchCount != "" {
parsedPrefetchCount, err := strconv.Atoi(prefetchCount)
if err == nil {
c.PrefetchCount = parsedPrefetchCount
}
}
if c.PrefetchCount == 0 {
c.PrefetchCount = c.ConsumerConcurrency
log.Info().Msgf("RABBIT_PREFETCH_COUNT is not set, defaulting to %d", c.PrefetchCount)
}

maxRetries := os.Getenv("RABBIT_MAX_RETRIES")
if maxRetries != "" {
parsedMaxRetries, err := strconv.Atoi(maxRetries)
Expand Down
2 changes: 1 addition & 1 deletion internal/events/rabbitmq/consumer/declares.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (r *rabbitmqConsumer) declare(routingKeys []string) error {
}

err = r.chManager.Channel.Qos(
r.config.ConsumerConcurrency, 0, false,
r.config.PrefetchCount, 0, false,
)
if err != nil {
return eris.Wrap(err, "failed to set QoS")
Expand Down

0 comments on commit 14922b2

Please sign in to comment.