Class: Lepus::Web::ManagementAPI
- Inherits:
-
Object
- Object
- Lepus::Web::ManagementAPI
- 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
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#vhost ⇒ Object
readonly
Returns the value of attribute vhost.
Instance Method Summary collapse
-
#connections ⇒ Array<Hash>
Fetch all connections.
-
#exchanges ⇒ Array<Hash>
Fetch all exchanges for the configured vhost.
-
#initialize(base_url: nil, vhost: "/") ⇒ ManagementAPI
constructor
A new instance of ManagementAPI.
-
#queue(name) ⇒ Hash?
Fetch a specific queue.
-
#queues ⇒ Array<Hash>
Fetch all queues for the configured vhost.
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_url ⇒ Object (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 |
#vhost ⇒ Object (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
#connections ⇒ Array<Hash>
Fetch all connections
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 |
#exchanges ⇒ Array<Hash>
Fetch all exchanges for the configured vhost
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
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 |
#queues ⇒ Array<Hash>
Fetch all queues for the configured vhost
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 |