Skip to content

Commit

Permalink
add flag to delete dlx before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandobandeira committed Dec 5, 2024
1 parent a8c1835 commit 4dd30d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/events/rabbitmq/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
DefaultMaxInterval = backoff.DefaultMaxInterval
// DefaultMaxRetries is the default max retries for the backoff
DefaultMaxRetries = 5
// DefaultDeleteDLX is the default value for deleting the DLX before creating it
DefaultDeleteDLX = false
)

type Config struct {
Expand All @@ -35,6 +37,8 @@ type Config struct {
RandomizationFactor float64
Multiplier float64
MaxInterval time.Duration

DeleteDLX bool
}

type RabbitmqConfigOption func(*Config)
Expand All @@ -50,6 +54,7 @@ func LoadConfig(log *zerolog.Logger, opts ...RabbitmqConfigOption) Config {
RandomizationFactor: DefaultRandomizationFactor,
Multiplier: DefaultMultiplier,
MaxInterval: DefaultMaxInterval,
DeleteDLX: DefaultDeleteDLX,
}

if c.ExchangeName == "" {
Expand Down Expand Up @@ -136,6 +141,14 @@ func LoadConfig(log *zerolog.Logger, opts ...RabbitmqConfigOption) Config {
}
}

deleteDLX := os.Getenv("RABBIT_DELETE_DLX")
if deleteDLX != "" {
parsedDeleteDLX, err := strconv.ParseBool(deleteDLX)
if err == nil {
c.DeleteDLX = parsedDeleteDLX
}
}

for _, opt := range opts {
opt(&c)
}
Expand Down
12 changes: 12 additions & 0 deletions internal/events/rabbitmq/consumer/declares.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ func (r *rabbitmqConsumer) deadLetterDeclare(dlxName string) error {
return eris.Wrap(err, "failed to declare exchange")
}

if r.config.DeleteDLX {
_, err = r.chManager.Channel.QueueDelete(
dlxName,
false,
false,
false,
)
if err != nil {
return eris.Wrap(err, "failed to delete queue")
}
}

_, err = r.chManager.Channel.QueueDeclare(
dlxName,
true,
Expand Down

0 comments on commit 4dd30d4

Please sign in to comment.