Skip to content

Commit 0afe635

Browse files
committed
feat(PubSub): Add SQS configuration
1 parent 56515a5 commit 0afe635

File tree

3 files changed

+319
-107
lines changed

3 files changed

+319
-107
lines changed

pkg/pubsub/config.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pubsub
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67
"time"
@@ -14,6 +15,8 @@ type (
1415
Config struct {
1516
// Kafka contains the configuration for Kafka client
1617
Kafka Kafka `mapstructure:"kafka"`
18+
// SQS contains the configuration for AWS SQS client
19+
SQS SQS `mapstructure:"sqs"`
1720
}
1821

1922
// Publisher contains the publisher specific configuration
@@ -135,6 +138,27 @@ type (
135138
// MetricsEnabled controls if metrics publishing is enabled or not
136139
MetricsEnabled bool `mapstructure:"metrics_enabled"`
137140
}
141+
142+
SQSSubscriber struct {
143+
Enabled bool `mapstructure:"enabled"`
144+
QueueURL string `mapstructure:"queue_url"`
145+
MaxMessages int `mapstructure:"max_messages"`
146+
Workers int `mapstructure:"workers"`
147+
148+
WaitTime time.Duration `mapstructure:"wait_time"`
149+
}
150+
151+
SQSPublisher struct {
152+
Enabled bool `mapstructure:"enabled"`
153+
QueueURL string `mapstructure:"queue_url"`
154+
}
155+
156+
SQS struct {
157+
// SQS Publisher specific configuration
158+
Publisher SQSPublisher
159+
// SQS Subscriber specific configuration
160+
Subscriber SQSSubscriber
161+
}
138162
)
139163

140164
const (
@@ -152,6 +176,8 @@ var (
152176
saslMechanismPlainString: Plain,
153177
saslMechanismAWsMskIamString: AWSMskIam,
154178
}
179+
180+
ErrEmptySQSQueueURL = errors.New("sqs queue url is empty")
155181
)
156182

157183
// NewConfig returns a new Config instance.
@@ -192,6 +218,12 @@ func (c *Config) validate() error {
192218
strings.Join(allowedMechanisms, ","),
193219
)
194220
}
221+
if c.SQS.Publisher.Enabled && c.SQS.Publisher.QueueURL == "" {
222+
return ErrEmptySQSQueueURL
223+
}
224+
if c.SQS.Subscriber.Enabled && c.SQS.Subscriber.QueueURL == "" {
225+
return ErrEmptySQSQueueURL
226+
}
195227

196228
return nil
197229
}

0 commit comments

Comments
 (0)