1package rabbithole 2 3import ( 4 "net/url" 5) 6 7// BriefConnectionDetails represents a brief (very incomplete) subset of connection information. 8type BriefConnectionDetails struct { 9 // Connection name 10 Name string `json:"name"` 11 // Client port 12 PeerPort Port `json:"peer_port"` 13 // Client host 14 PeerHost string `json:"peer_host"` 15} 16 17// ChannelInfo represents an AMQP 0-9-1 channel. 18type ChannelInfo struct { 19 // Channel number 20 Number int `json:"number"` 21 // Channel name 22 Name string `json:"name"` 23 24 // basic.qos (prefetch count) value used 25 PrefetchCount int `json:"prefetch_count"` 26 // How many consumers does this channel have 27 ConsumerCount int `json:"consumer_count"` 28 29 // Number of unacknowledged messages on this channel 30 UnacknowledgedMessageCount int `json:"messages_unacknowledged"` 31 // Number of messages on this channel unconfirmed to publishers 32 UnconfirmedMessageCount int `json:"messages_unconfirmed"` 33 // Number of messages on this channel uncommited to message store 34 UncommittedMessageCount int `json:"messages_uncommitted"` 35 // Number of acks on this channel uncommited to message store 36 UncommittedAckCount int `json:"acks_uncommitted"` 37 38 // TODO(mk): custom deserializer to date/time? 39 IdleSince string `json:"idle_since"` 40 41 // True if this channel uses publisher confirms 42 UsesPublisherConfirms bool `json:"confirm"` 43 // True if this channel uses transactions 44 Transactional bool `json:"transactional"` 45 // True if this channel is blocked via channel.flow 46 ClientFlowBlocked bool `json:"client_flow_blocked"` 47 48 User string `json:"user"` 49 Vhost string `json:"vhost"` 50 Node string `json:"node"` 51 52 ConnectionDetails BriefConnectionDetails `json:"connection_details"` 53} 54 55// 56// GET /api/channels 57// 58 59// ListChannels returns information about all open channels. 60func (c *Client) ListChannels() (rec []ChannelInfo, err error) { 61 req, err := newGETRequest(c, "channels") 62 if err != nil { 63 return []ChannelInfo{}, err 64 } 65 66 if err = executeAndParseRequest(c, req, &rec); err != nil { 67 return []ChannelInfo{}, err 68 } 69 70 return rec, nil 71} 72 73// 74// GET /api/channels/{name} 75// 76 77// GetChannel returns channel information. 78func (c *Client) GetChannel(name string) (rec *ChannelInfo, err error) { 79 req, err := newGETRequest(c, "channels/"+url.PathEscape(name)) 80 if err != nil { 81 return nil, err 82 } 83 84 if err = executeAndParseRequest(c, req, &rec); err != nil { 85 return nil, err 86 } 87 88 return rec, nil 89} 90