This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
forked from asticode/go-astiamqp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
94 lines (80 loc) · 2.16 KB
/
configuration.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package astiamqp
import (
"flag"
"github.com/streadway/amqp"
)
// Constants
const (
ExchangeTypeDirect ExchangeType = "direct"
ExchangeTypeFanout ExchangeType = "fanout"
ExchangeTypeHeaders ExchangeType = "headers"
ExchangeTypeTopic ExchangeType = "topic"
)
// Flags
var (
Addr = flag.String("amqp-addr", "", "the amqp addr")
Password = flag.String("amqp-password", "", "the amqp password")
Username = flag.String("amqp-username", "", "the amqp username")
)
// Configuration represents the AMQP configuration
type Configuration struct {
Addr string `toml:"addr"`
Password string `toml:"password"`
QOS *ConfigurationQOS `toml:"qos"`
Username string `toml:"username"`
}
// ConfigurationQOS represents the AMQP QOS configuration
type ConfigurationQOS struct {
Global bool `toml:"global"`
PrefetchCount int `toml:"prefetch_count"`
PrefetchSize int `toml:"prefetch_size"`
}
// FlagConfig returns an AMQP config based on flags
func FlagConfig() Configuration {
return Configuration{
Addr: *Addr,
Password: *Password,
Username: *Username,
}
}
// ConfigurationExchange represents an exchange configuration
type ConfigurationExchange struct {
Arguments Table
AutoDeleted bool
Durable bool
Internal bool
Name string
NoWait bool
Type ExchangeType
}
// ExchangeType represents an exchange type
type ExchangeType string
// Table wraps amqp.Table
type Table amqp.Table
// ConfigurationQueue represents a queue configuration
type ConfigurationQueue struct {
Arguments Table
AutoDeleted bool
Durable bool
Exclusive bool
Name string
NoWait bool
}
// ConfigurationConsumer represents a consumer configuration
type ConfigurationConsumer struct {
Arguments Table
AutoAck bool
Exchange ConfigurationExchange
Exclusive bool
Handler Handler
NoLocal bool
NoWait bool
Queue ConfigurationQueue
RoutingKey string
}
// Handler handles a message
type Handler func(msg []byte, routingKey string, a Acknowledger) error
// ConfigurationProducer represents a producer configuration
type ConfigurationProducer struct {
Exchange ConfigurationExchange
}