-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel.go
149 lines (122 loc) · 3.37 KB
/
model.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package gorabbit
import (
"strconv"
"time"
amqp "github.com/rabbitmq/amqp091-go"
)
type SchemaDefinitions struct {
Exchanges []struct {
Name string `json:"name"`
Vhost string `json:"vhost"`
Type string `json:"type"`
Durable bool `json:"durable"`
AutoDelete bool `json:"auto_delete"`
Internal bool `json:"internal"`
Arguments struct {
} `json:"arguments"`
} `json:"exchanges"`
Queues []struct {
Name string `json:"name"`
Vhost string `json:"vhost"`
Durable bool `json:"durable"`
AutoDelete bool `json:"auto_delete"`
Arguments struct {
} `json:"arguments"`
} `json:"queues"`
Bindings []struct {
Source string `json:"source"`
Vhost string `json:"vhost"`
Destination string `json:"destination"`
DestinationType string `json:"destination_type"`
RoutingKey string `json:"routing_key"`
Arguments struct {
} `json:"arguments"`
} `json:"bindings"`
}
type ExchangeConfig struct {
Name string `yaml:"name"`
Type ExchangeType `yaml:"type"`
Persisted bool `yaml:"persisted"`
Args map[string]interface{} `yaml:"args"`
}
type QueueConfig struct {
Name string `yaml:"name"`
Durable bool `yaml:"durable"`
Exclusive bool `yaml:"exclusive"`
AutoDelete bool `yaml:"autoDelete"`
Args map[string]interface{} `yaml:"args"`
Bindings []BindingConfig `yaml:"bindings"`
}
type BindingConfig struct {
RoutingKey string `yaml:"routing_key"`
Exchange string `yaml:"exchange"`
}
type PublishingOptions struct {
MessagePriority *MessagePriority
DeliveryMode *DeliveryMode
TTL *time.Duration
}
func SendOptions() *PublishingOptions {
return &PublishingOptions{}
}
func (m *PublishingOptions) priority() uint8 {
if m.MessagePriority == nil {
return PriorityMedium.Uint8()
}
return m.MessagePriority.Uint8()
}
func (m *PublishingOptions) mode() uint8 {
if m.DeliveryMode == nil {
return Persistent.Uint8()
}
return m.DeliveryMode.Uint8()
}
func (m *PublishingOptions) ttl() string {
if m.TTL == nil {
return ""
}
return strconv.FormatInt(m.TTL.Milliseconds(), 10)
}
func (m *PublishingOptions) SetPriority(priority MessagePriority) *PublishingOptions {
m.MessagePriority = &priority
return m
}
func (m *PublishingOptions) SetMode(mode DeliveryMode) *PublishingOptions {
m.DeliveryMode = &mode
return m
}
func (m *PublishingOptions) SetTTL(ttl time.Duration) *PublishingOptions {
m.TTL = &ttl
return m
}
type consumptionHealth map[string]bool
func (s consumptionHealth) IsHealthy() bool {
for _, v := range s {
if !v {
return false
}
}
return true
}
func (s consumptionHealth) AddSubscription(queue string, err error) {
s[queue] = err == nil
}
type mqttPublishing struct {
Exchange string
RoutingKey string
Mandatory bool
Immediate bool
Msg amqp.Publishing
}
func (m mqttPublishing) HashCode() string {
return m.Msg.MessageId
}
type RabbitMQEnvs struct {
Host string `env:"RABBITMQ_HOST"`
Port uint `env:"RABBITMQ_PORT"`
Username string `env:"RABBITMQ_USERNAME"`
Password string `env:"RABBITMQ_PASSWORD"`
Vhost string `env:"RABBITMQ_VHOST"`
UseTLS bool `env:"RABBITMQ_USE_TLS"`
ConnectionName string `env:"RABBITMQ_CONNECTION_NAME"`
}