forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumers.go
77 lines (65 loc) · 2.23 KB
/
consumers.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
package rabbithole
import (
"net/url"
)
// AcknowledgementMode specifies an acknowledgement mode used by
// a consumer. Learn more at https://www.rabbitmq.com/confirms.html.
type AcknowledgementMode bool
const (
// ManualAcknowledgement requires the consumer to explicitly
// acknowledge processed deliveries.
ManualAcknowledgement AcknowledgementMode = true
// AutomaticAcknowledgment means that deliveries sent
// to the consumer will be considered processed immediately.
// Explicit acks from the client are not needed or expected
// by the server.
AutomaticAcknowledgment AcknowledgementMode = false
)
// BriefQueueInfo represents a fully qualified queue name.
type BriefQueueInfo struct {
Name string `json:"name"`
Vhost string `json:"vhost"`
}
// BriefChannelDetail represents a channel with a limited
// number of metrics.
type BriefChannelDetail struct {
ConnectionName string `json:"connection_name"`
Name string `json:"name"`
Node string `json:"node"`
Number int `json:"number"`
PeerHost string `json:"peer_host"`
PeerPort int `json:"peer_port"`
User string `json:"user"`
}
// ConsumerInfo represents a consumer.
type ConsumerInfo struct {
Arguments map[string]interface{} `json:"arguments"`
AcknowledgementMode AcknowledgementMode `json:"ack_required"`
ChannelDetails BriefChannelDetail `json:"channel_details"`
ConsumerTag string `json:"consumer_tag"`
Exclusive bool `json:"exclusive"`
PrefetchCount int `json:"prefetch_count"`
Queue BriefQueueInfo `json:"queue"`
}
// ListConsumers lists all consumers in the cluster.
func (c *Client) ListConsumers() (rec []ConsumerInfo, err error) {
req, err := newGETRequest(c, "consumers")
if err != nil {
return
}
if err = executeAndParseRequest(c, req, &rec); err != nil {
return
}
return
}
// ListConsumersIn lists all consumers in a virtual host.
func (c *Client) ListConsumersIn(vhost string) (rec []ConsumerInfo, err error) {
req, err := newGETRequest(c, "consumers/"+url.PathEscape(vhost))
if err != nil {
return
}
if err = executeAndParseRequest(c, req, &rec); err != nil {
return
}
return
}