Class: Lepus::Web::ManagementAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/lepus/web/management_api.rb

Overview

HTTP client for RabbitMQ Management API. Fetches queue and connection statistics.

Defined Under Namespace

Classes: AuthenticationError, ConnectionError, Error, NotFoundError

Constant Summary collapse

DEFAULT_PORT =
15672

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, vhost: "/") ⇒ ManagementAPI

Returns a new instance of ManagementAPI.



16
17
18
19
# File 'lib/lepus/web/management_api.rb', line 16

def initialize(base_url: nil, vhost: "/")
  @base_url = base_url || derive_management_url
  @vhost = vhost
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



14
15
16
# File 'lib/lepus/web/management_api.rb', line 14

def base_url
  @base_url
end

#vhostObject (readonly)

Returns the value of attribute vhost.



14
15
16
# File 'lib/lepus/web/management_api.rb', line 14

def vhost
  @vhost
end

Instance Method Details

#connectionsArray<Hash>

Fetch all connections

Returns:

  • (Array<Hash>)

    array of connection data



43
44
45
46
47
48
# File 'lib/lepus/web/management_api.rb', line 43

def connections
  data = get("/api/connections")
  return [] unless data.is_a?(Array)

  data.map { |c| normalize_connection(c) }
end

#exchangesArray<Hash>

Fetch all exchanges for the configured vhost

Returns:

  • (Array<Hash>)

    array of exchange data



32
33
34
35
36
37
38
39
# File 'lib/lepus/web/management_api.rb', line 32

def exchanges
  data = get("/api/exchanges/#{encode_vhost}")
  return [] unless data.is_a?(Array)

  data
    .reject { |e| e["name"].to_s.empty? || e["name"].to_s.start_with?("amq.") }
    .map { |e| normalize_exchange(e) }
end

#queue(name) ⇒ Hash?

Fetch a specific queue

Parameters:

  • name (String)

    queue name

Returns:

  • (Hash, nil)

    queue data or nil if not found



53
54
55
56
57
58
# File 'lib/lepus/web/management_api.rb', line 53

def queue(name)
  data = get("/api/queues/#{encode_vhost}/#{encode_name(name)}")
  normalize_queue(data) if data
rescue NotFoundError
  nil
end

#queuesArray<Hash>

Fetch all queues for the configured vhost

Returns:

  • (Array<Hash>)

    array of queue data



23
24
25
26
27
28
# File 'lib/lepus/web/management_api.rb', line 23

def queues
  data = get("/api/queues/#{encode_vhost}")
  return [] unless data.is_a?(Array)

  data.map { |q| normalize_queue(q) }
end