Skip to content

Commit

Permalink
adds option for max priority
Browse files Browse the repository at this point in the history
NOTE: this is a breaking change, the max priority was previous
defaulting to 10
  • Loading branch information
markcsims committed Oct 21, 2024
1 parent cc88cc3 commit d6b1370
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type NewConsumerConfig struct {
requeueLimit int
serviceName string
prefetch int
maxPriority uint8 // Optional
}

// NewConsumerConfig config for establishing a RabbitMq consumer
Expand Down Expand Up @@ -128,7 +129,7 @@ func (p *NewConsumerConfig) Config() ConsumerConfig {
RequeueTTL: p.requeueTTL,
RetryLimit: p.requeueLimit,
Patterns: p.patterns,
MaxPriority: 10,
MaxPriority: p.maxPriority,
PrefetchCount: p.prefetch,
},
}
Expand Down
32 changes: 32 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,38 @@ func TestItSetsPatternsOnQueue(t *testing.T) {
}
consumerConfig := c.Config()

if consumerConfig.queue.MaxPriority != 0 {
t.Error("Expected max priority to be set to 0 got", consumerConfig.queue.MaxPriority)
}
if len(consumerConfig.queue.Patterns) != 1 {
t.Fatal("There should be one pattern set")
}

if consumerConfig.queue.Patterns[0] != pattern {
t.Error("Unexpected pattern, expected", pattern, "but got", consumerConfig.queue.Patterns[0])
}
}

func TestItSetsMaxPriority(t *testing.T) {
logger := helpers.NewTestLogger(t)
pattern := "pretty.pattern"
c := NewConsumerConfig{
URL: testRabbitURI,
exchangeName: "exchange",
exchangeType: Fanout,
patterns: []string{pattern},
logger: logger,
requeueTTL: 200,
requeueLimit: testRequeueLimit,
serviceName: "service",
prefetch: defaultPrefetch,
maxPriority: 7,
}
consumerConfig := c.Config()

if consumerConfig.queue.MaxPriority != 7 {
t.Error("Expected max priority to be set to 7 got", consumerConfig.queue.MaxPriority)
}
if len(consumerConfig.queue.Patterns) != 1 {
t.Fatal("There should be one pattern set")
}
Expand Down

0 comments on commit d6b1370

Please sign in to comment.