summaryrefslogtreecommitdiff
path: root/plugins/jobs/drivers/amqp/config.go
blob: 7befb3c8a03ca90f51b4ef3a9cbb79d3caebcb85 (plain)
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
package amqp

// pipeline rabbitmq info
const (
	exchangeKey  string = "exchange"
	exchangeType string = "exchange-type"
	queue        string = "queue"
	routingKey   string = "routing-key"
	prefetch     string = "prefetch"
	exclusive    string = "exclusive"
	priority     string = "priority"

	dlx           string = "x-dead-letter-exchange"
	dlxRoutingKey string = "x-dead-letter-routing-key"
	dlxTTL        string = "x-message-ttl"
	dlxExpires    string = "x-expires"

	contentType string = "application/octet-stream"
)

type GlobalCfg struct {
	Addr string `mapstructure:"addr"`
}

// Config is used to parse pipeline configuration
type Config struct {
	PrefetchCount int    `mapstructure:"pipeline_size"`
	Queue         string `mapstructure:"queue"`
	Priority      int64  `mapstructure:"priority"`
	Exchange      string `mapstructure:"exchange"`
	ExchangeType  string `mapstructure:"exchange_type"`
	RoutingKey    string `mapstructure:"routing_key"`
	Exclusive     bool   `mapstructure:"exclusive"`
}

func (c *Config) InitDefault() {
	if c.ExchangeType == "" {
		c.ExchangeType = "direct"
	}

	if c.Exchange == "" {
		c.Exchange = "default"
	}

	if c.PrefetchCount == 0 {
		c.PrefetchCount = 100
	}

	if c.Priority == 0 {
		c.Priority = 10
	}
}

func (c *GlobalCfg) InitDefault() {
	if c.Addr == "" {
		c.Addr = "amqp://guest:guest@localhost:5672/"
	}
}