Skip to content

Commit

Permalink
list vhost connections
Browse files Browse the repository at this point in the history
  • Loading branch information
needsalongholiday authored and michaelklishin committed Nov 1, 2021
1 parent 8d3992d commit 00d29ef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,36 @@ var _ = Describe("RabbitMQ HTTP API client", func() {
})
})

Context("GET /vhosts/{name}/connections", func() {
It("returns decoded response", func() {

conn := openConnection("rabbit/hole")
defer conn.Close()

ch, err := conn.Channel()
Ω(err).Should(BeNil())
defer ch.Close()

err = ch.Publish("",
"",
false,
false,
amqp.Publishing{Body: []byte("")})
Ω(err).Should(BeNil())

// give internal events a moment to be
// handled
awaitEventPropagation()

xs, err := rmqc.ListVhostConnections("rabbit/hole")
Ω(err).Should(BeNil())

c1 := xs[0]
Ω(c1.Protocol).Should(Equal("AMQP 0-9-1"))
Ω(c1.User).Should(Equal("guest"))
})
})

Context("vhost-limits", func() {
maxConnections := 1
maxQueues := 2
Expand Down
19 changes: 19 additions & 0 deletions vhosts_connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package rabbithole

import (
"net/url"
)

// ListVhostConnections returns the current connections to a specified vhost
func (c *Client) ListVhostConnections(vhostname string) (rec []ConnectionInfo, err error) {
req, err := newGETRequest(c, "vhosts/"+url.PathEscape(vhostname)+"/connections")
if err != nil {
return []ConnectionInfo{}, err
}

if err = executeAndParseRequest(c, req, &rec); err != nil {
return []ConnectionInfo{}, err
}

return rec, nil
}

0 comments on commit 00d29ef

Please sign in to comment.