Skip to content

Commit

Permalink
exports config properties
Browse files Browse the repository at this point in the history
  • Loading branch information
markcsims committed Oct 21, 2024
1 parent af37482 commit ead44c3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 98 deletions.
74 changes: 37 additions & 37 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ type ConsumerConfig struct {
}
type NewPublisherConfig struct {
URL string
exchangeName string
exchangeType ExchangeType
confirmable bool
logger logger
ExchangeName string
ExchangeType ExchangeType
Confirmable bool
Logger logger
}

// NewPublisherConfig returns a PublisherConfig derived from the consumer config. This config can be used to create a Publisher to Publish to this consumer
func (c ConsumerConfig) NewPublisherConfig() PublisherConfig {
nc := NewPublisherConfig{
URL: c.URL,
exchangeName: c.exchange.Name,
exchangeType: c.exchange.Type,
confirmable: false,
logger: c.Logger,
ExchangeName: c.exchange.Name,
ExchangeType: c.exchange.Type,
Confirmable: false,
Logger: c.Logger,
}
return nc.Config()
}
Expand All @@ -75,62 +75,62 @@ func (c ConsumerConfig) NewPublisherConfig() PublisherConfig {
func (p *NewPublisherConfig) Config() PublisherConfig {

return PublisherConfig{
confirmable: p.confirmable,
confirmable: p.Confirmable,
connectionConfig: connectionConfig{
URL: p.URL,
Logger: p.logger,
Logger: p.Logger,
},
exchange: exchange{
Name: p.exchangeName,
Type: p.exchangeType,
Name: p.ExchangeName,
Type: p.ExchangeType,
},
}
}

type NewConsumerConfig struct {
URL string
exchangeName string
exchangeType ExchangeType
patterns []string
logger logger
requeueTTL int16
requeueLimit int
serviceName string
prefetch int
maxPriority uint8 // Optional
ExchangeName string
ExchangeType ExchangeType
Patterns []string
Logger logger
RequeueTTL int16
RequeueLimit int
ServiceName string
Prefetch int
MaxPriority uint8 // Optional
}

// NewConsumerConfig config for establishing a RabbitMq consumer
func (p *NewConsumerConfig) Config() ConsumerConfig {

if len(p.patterns) == 0 {
p.logger.Info("Executive decision made! You did not supply a pattern so we have added a default of '#'")
p.patterns = append(p.patterns, "#") //testme
if len(p.Patterns) == 0 {
p.Logger.Info("Executive decision made! You did not supply a pattern so we have added a default of '#'")
p.Patterns = append(p.Patterns, "#") //testme
}

queueName := fmt.Sprintf("%s-for-%s", p.exchangeName, p.serviceName)
queueName := fmt.Sprintf("%s-for-%s", p.ExchangeName, p.ServiceName)

return ConsumerConfig{
connectionConfig: connectionConfig{
URL: p.URL,
Logger: p.logger,
Logger: p.Logger,
},
exchange: exchange{
Name: p.exchangeName,
RetryNow: fmt.Sprintf("%s-for-%s-retry-now", p.exchangeName, p.serviceName),
RetryLater: fmt.Sprintf("%s-for-%s-retry-%dms-later", p.exchangeName, p.serviceName, p.requeueTTL),
DLE: fmt.Sprintf("%s-for-%s-dle", p.exchangeName, p.serviceName),
Type: p.exchangeType,
Name: p.ExchangeName,
RetryNow: fmt.Sprintf("%s-for-%s-retry-now", p.ExchangeName, p.ServiceName),
RetryLater: fmt.Sprintf("%s-for-%s-retry-%dms-later", p.ExchangeName, p.ServiceName, p.RequeueTTL),
DLE: fmt.Sprintf("%s-for-%s-dle", p.ExchangeName, p.ServiceName),
Type: p.ExchangeType,
},
queue: queue{
Name: queueName,
DLQ: queueName + "-dlq",
RetryLater: fmt.Sprintf("%s-retry-%dms-later", queueName, p.requeueTTL),
RequeueTTL: p.requeueTTL,
RetryLimit: p.requeueLimit,
Patterns: p.patterns,
MaxPriority: p.maxPriority,
PrefetchCount: p.prefetch,
RetryLater: fmt.Sprintf("%s-retry-%dms-later", queueName, p.RequeueTTL),
RequeueTTL: p.RequeueTTL,
RetryLimit: p.RequeueLimit,
Patterns: p.Patterns,
MaxPriority: p.MaxPriority,
PrefetchCount: p.Prefetch,
},
}
}
66 changes: 33 additions & 33 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ func TestItDerivesConsumerExchanges(t *testing.T) {

c := NewConsumerConfig{
URL: testRabbitURI,
exchangeName: "producer-stuff",
exchangeType: Fanout,
patterns: noPatterns,
logger: logger,
requeueTTL: 200,
requeueLimit: testRequeueLimit,
serviceName: "service",
prefetch: defaultPrefetch,
ExchangeName: "producer-stuff",
ExchangeType: Fanout,
Patterns: noPatterns,
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()

Expand Down Expand Up @@ -70,14 +70,14 @@ func TestItSetsPatternToHashWhenNoneSupplied(t *testing.T) {

c := NewConsumerConfig{
URL: testRabbitURI,
exchangeName: "exchange",
exchangeType: Fanout,
patterns: noPatterns,
logger: logger,
requeueTTL: 200,
requeueLimit: testRequeueLimit,
serviceName: "service",
prefetch: defaultPrefetch,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: noPatterns,
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()

Expand All @@ -95,14 +95,14 @@ func TestItSetsPatternsOnQueue(t *testing.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,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: []string{pattern},
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
}
consumerConfig := c.Config()

Expand All @@ -123,15 +123,15 @@ func TestItSetsMaxPriority(t *testing.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,
ExchangeName: "exchange",
ExchangeType: Fanout,
Patterns: []string{pattern},
Logger: logger,
RequeueTTL: 200,
RequeueLimit: testRequeueLimit,
ServiceName: "service",
Prefetch: defaultPrefetch,
MaxPriority: 7,
}
consumerConfig := c.Config()

Expand Down
16 changes: 8 additions & 8 deletions consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,14 @@ func newTestConsumerConfig(t *testing.T, config consumerConfigOptions) ConsumerC
c :=
NewConsumerConfig{
URL: "amqp://guest:guest@rabbitmq:5672/",
exchangeName: config.ExchangeName,
exchangeType: config.ExchangeType,
patterns: config.Patterns,
logger: logger,
requeueTTL: config.RequeueTTL,
requeueLimit: config.Retries,
serviceName: config.ServiceName,
prefetch: defaultPrefetch,
ExchangeName: config.ExchangeName,
ExchangeType: config.ExchangeType,
Patterns: config.Patterns,
Logger: logger,
RequeueTTL: config.RequeueTTL,
RequeueLimit: config.Retries,
ServiceName: config.ServiceName,
Prefetch: defaultPrefetch,
}
return c.Config()
}
Expand Down
24 changes: 12 additions & 12 deletions example_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func ExampleConsumer() {

c := NewConsumerConfig{
URL: testRabbitURI,
exchangeName: "test-example-exchange",
exchangeType: Fanout,
patterns: noPatterns,
logger: &SimpleLogger{io.Discard},
requeueTTL: testRequeueTTL,
requeueLimit: testRequeueLimit,
serviceName: serviceName,
prefetch: defaultPrefetch,
ExchangeName: "test-example-exchange",
ExchangeType: Fanout,
Patterns: noPatterns,
Logger: &SimpleLogger{io.Discard},
RequeueTTL: testRequeueTTL,
RequeueLimit: testRequeueLimit,
ServiceName: serviceName,
Prefetch: defaultPrefetch,
}
// Create a consumer config
config := c.Config()
Expand All @@ -62,10 +62,10 @@ func ExampleConsumer() {
// We can now publish to the same exchange for fun
pc := NewPublisherConfig{
URL: config.URL,
exchangeName: config.exchange.Name,
exchangeType: config.exchange.Type,
confirmable: false,
logger: config.Logger,
ExchangeName: config.exchange.Name,
ExchangeType: config.exchange.Type,
Confirmable: false,
Logger: config.Logger,
}
publisherConfig := pc.Config()
publisher, err := NewPublisher(publisherConfig)
Expand Down
16 changes: 8 additions & 8 deletions publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func TestNakedPublisher(t *testing.T) {
expectedExchangeName := "chris-rulz" + randomString(5)
c := NewPublisherConfig{
URL: testRabbitURI,
exchangeName: expectedExchangeName,
exchangeType: Fanout,
confirmable: true,
logger: helpers.NewTestLogger(t),
ExchangeName: expectedExchangeName,
ExchangeType: Fanout,
Confirmable: true,
Logger: helpers.NewTestLogger(t),
}
config := c.Config()

Expand All @@ -38,10 +38,10 @@ func TestNotReadyPublisherErrorsOnPublish(t *testing.T) {
expectedExchangeName := "chris-rulz" + randomString(5)
c := NewPublisherConfig{
URL: testRabbitURI,
exchangeName: expectedExchangeName,
exchangeType: Fanout,
confirmable: true,
logger: helpers.NewTestLogger(t),
ExchangeName: expectedExchangeName,
ExchangeType: Fanout,
Confirmable: true,
Logger: helpers.NewTestLogger(t),
}
config := c.Config()

Expand Down

0 comments on commit ead44c3

Please sign in to comment.