From d6b1370f04f246368529a1408657076741ef1bec Mon Sep 17 00:00:00 2001 From: Mark Sims Date: Mon, 21 Oct 2024 13:04:01 +0100 Subject: [PATCH] adds option for max priority NOTE: this is a breaking change, the max priority was previous defaulting to 10 --- config.go | 3 ++- config_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index c5771ae..4bda5a4 100644 --- a/config.go +++ b/config.go @@ -97,6 +97,7 @@ type NewConsumerConfig struct { requeueLimit int serviceName string prefetch int + maxPriority uint8 // Optional } // NewConsumerConfig config for establishing a RabbitMq consumer @@ -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, }, } diff --git a/config_test.go b/config_test.go index ca4a88e..609a6ef 100644 --- a/config_test.go +++ b/config_test.go @@ -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") }