-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
72 lines (59 loc) · 1.29 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package nats
import (
"time"
"gofr.dev/pkg/gofr/datasource/pubsub"
)
const batchSize = 100
// Config defines the Client configuration.
type Config struct {
Server string
CredsFile string
Stream StreamConfig
Consumer string
MaxWait time.Duration
MaxPullWait int
}
// StreamConfig holds stream settings for NATS JetStream.
type StreamConfig struct {
Stream string
Subjects []string
MaxDeliver int
MaxWait time.Duration
MaxBytes int64
}
// New creates a new Client.
func New(cfg *Config, logger pubsub.Logger) *PubSubWrapper {
if cfg == nil {
cfg = &Config{}
}
client := &Client{
Config: cfg,
subManager: newSubscriptionManager(batchSize),
logger: logger,
}
return &PubSubWrapper{Client: client}
}
// ValidateConfigs validates the configuration for NATS JetStream.
func ValidateConfigs(conf *Config) error {
if conf.Server == "" {
return errServerNotProvided
}
if len(conf.Stream.Subjects) == 0 {
return errSubjectsNotProvided
}
if conf.Consumer == "" {
return errConsumerNotProvided
}
return nil
}
// DefaultConfig returns a Config with default values.
func DefaultConfig() *Config {
return &Config{
MaxWait: 5 * time.Second,
MaxPullWait: 10,
Stream: StreamConfig{
MaxDeliver: 3,
MaxWait: 30 * time.Second,
},
}
}