Class: RabbitMQ::HTTP::Client
- Inherits:
-
Object
- Object
- RabbitMQ::HTTP::Client
- Defined in:
- lib/rabbitmq/http/client.rb,
lib/rabbitmq/http/client/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
API.
Class Method Summary collapse
Instance Method Summary collapse
- #aliveness_test(vhost) ⇒ Object
- #bind_queue(vhost, queue, exchange, routing_key, arguments = []) ⇒ Object
- #channel_info(name) ⇒ Object
- #clear_parameters_of(component, vhost, name) ⇒ Object
- #clear_permissions_of(vhost, user) ⇒ Object
- #clear_policies_of(vhost, name) ⇒ Object
- #close_connection(name) ⇒ Object
- #connection_info(name) ⇒ Object
- #create_vhost(name) ⇒ Object
- #declare_queue(vhost, name, attributes) ⇒ Object
- #delete_queue(vhost, name) ⇒ Object
- #delete_queue_binding(vhost, queue, exchange, properties_key) ⇒ Object
- #delete_user(name) ⇒ Object
- #delete_vhost(name) ⇒ Object
-
#enabled_protocols ⇒ Array<String>
Returns a list of messaging protocols supported by the node (or cluster).
- #exchange_info(vhost, name) ⇒ Object
- #get_messages(vhost, name, options) ⇒ Object
-
#initialize(endpoint, options = {}) ⇒ Client
constructor
A new instance of Client.
- #list_bindings(vhost = nil) ⇒ Object
- #list_bindings_between_queue_and_exchange(vhost, queue, exchange) ⇒ Object
- #list_bindings_by_destination(vhost, exchange) ⇒ Object
- #list_bindings_by_source(vhost, exchange) ⇒ Object
- #list_channels ⇒ Object
- #list_connections ⇒ Object
- #list_definitions ⇒ Object
- #list_exchanges(vhost = nil) ⇒ Object
- #list_extensions ⇒ Object
- #list_nodes ⇒ Object
- #list_parameters(component = nil) ⇒ Object
- #list_parameters_of(component, vhost, name = nil) ⇒ Object
- #list_permissions(vhost = nil) ⇒ Object
- #list_permissions_of(vhost, user) ⇒ Object
- #list_policies(vhost = nil) ⇒ Object
- #list_policies_of(vhost, name = nil) ⇒ Object
- #list_queue_bindings(vhost, queue) ⇒ Object
- #list_queues(vhost = nil) ⇒ Object
- #list_users ⇒ Object
- #list_vhosts ⇒ Object
- #node_info(name) ⇒ Object
- #overview ⇒ Object
-
#protocol_ports ⇒ Hash<String, Integer>
Returns a hash of protocol => port.
- #purge_queue(vhost, name) ⇒ Object
- #queue_binding_info(vhost, queue, exchange, properties_key) ⇒ Object
- #queue_info(vhost, name) ⇒ Object
- #update_parameters_of(component, vhost, name, attributes) ⇒ Object
- #update_permissions_of(vhost, user, attributes) ⇒ Object
- #update_policies_of(vhost, name, attributes) ⇒ Object
- #update_user(name, attributes) ⇒ Object (also: #create_user)
- #upload_definitions(defs) ⇒ Object
- #user_info(name) ⇒ Object
- #user_permissions(name) ⇒ Object
- #vhost_info(name) ⇒ Object
- #whoami ⇒ Object
Constructor Details
#initialize(endpoint, options = {}) ⇒ Client
Returns a new instance of Client.
24 25 26 27 28 29 |
# File 'lib/rabbitmq/http/client.rb', line 24 def initialize(endpoint, = {}) @endpoint = endpoint @options = initialize_connection(endpoint, ) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
API
18 19 20 |
# File 'lib/rabbitmq/http/client.rb', line 18 def endpoint @endpoint end |
Class Method Details
.connect(endpoint, options = {}) ⇒ Object
20 21 22 |
# File 'lib/rabbitmq/http/client.rb', line 20 def self.connect(endpoint, = {}) new(endpoint, ) end |
Instance Method Details
#aliveness_test(vhost) ⇒ Object
347 348 349 350 |
# File 'lib/rabbitmq/http/client.rb', line 347 def aliveness_test(vhost) r = @connection.get("/api/aliveness-test/#{uri_encode(vhost)}") r.body["status"] == "ok" end |
#bind_queue(vhost, queue, exchange, routing_key, arguments = []) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/rabbitmq/http/client.rb', line 186 def bind_queue(vhost, queue, exchange, routing_key, arguments = []) resp = @connection.post("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}") do |req| req.headers['Content-Type'] = 'application/json' req.body = MultiJson.dump({ routing_key: routing_key, arguments: arguments }) end resp.headers['location'] end |
#channel_info(name) ⇒ Object
99 100 101 |
# File 'lib/rabbitmq/http/client.rb', line 99 def channel_info(name) decode_resource(@connection.get("/api/channels/#{uri_encode(name)}")) end |
#clear_parameters_of(component, vhost, name) ⇒ Object
341 342 343 |
# File 'lib/rabbitmq/http/client.rb', line 341 def clear_parameters_of(component, vhost, name) decode_resource(@connection.delete("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}")) end |
#clear_permissions_of(vhost, user) ⇒ Object
244 245 246 |
# File 'lib/rabbitmq/http/client.rb', line 244 def (vhost, user) decode_resource(@connection.delete("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}")) end |
#clear_policies_of(vhost, name) ⇒ Object
308 309 310 |
# File 'lib/rabbitmq/http/client.rb', line 308 def clear_policies_of(vhost, name) decode_resource(@connection.delete("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}")) end |
#close_connection(name) ⇒ Object
91 92 93 |
# File 'lib/rabbitmq/http/client.rb', line 91 def close_connection(name) decode_resource(@connection.delete("/api/connections/#{uri_encode(name)}")) end |
#connection_info(name) ⇒ Object
87 88 89 |
# File 'lib/rabbitmq/http/client.rb', line 87 def connection_info(name) decode_resource(@connection.get("/api/connections/#{uri_encode(name)}")) end |
#create_vhost(name) ⇒ Object
209 210 211 212 213 214 |
# File 'lib/rabbitmq/http/client.rb', line 209 def create_vhost(name) response = @connection.put("/api/vhosts/#{uri_encode(name)}") do |req| req.headers['Content-Type'] = "application/json" end decode_resource(response) end |
#declare_queue(vhost, name, attributes) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/rabbitmq/http/client.rb', line 139 def declare_queue(vhost, name, attributes) response = @connection.put("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump(attributes) end decode_resource(response) end |
#delete_queue(vhost, name) ⇒ Object
147 148 149 |
# File 'lib/rabbitmq/http/client.rb', line 147 def delete_queue(vhost, name) decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}")) end |
#delete_queue_binding(vhost, queue, exchange, properties_key) ⇒ Object
194 195 196 197 |
# File 'lib/rabbitmq/http/client.rb', line 194 def delete_queue_binding(vhost, queue, exchange, properties_key) resp = @connection.delete("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}") resp.success? end |
#delete_user(name) ⇒ Object
267 268 269 |
# File 'lib/rabbitmq/http/client.rb', line 267 def delete_user(name) decode_resource(@connection.delete("/api/users/#{uri_encode(name)}")) end |
#delete_vhost(name) ⇒ Object
216 217 218 |
# File 'lib/rabbitmq/http/client.rb', line 216 def delete_vhost(name) decode_resource(@connection.delete("/api/vhosts/#{uri_encode(name)}")) end |
#enabled_protocols ⇒ Array<String>
Returns a list of messaging protocols supported by the node (or cluster).
Common values are:
-
amqp
-
amqp/ssl
-
mqtt
-
stomp
The exact value depends on RabbitMQ configuration and enabled plugins.
49 50 51 52 53 |
# File 'lib/rabbitmq/http/client.rb', line 49 def enabled_protocols self.overview.listeners. map { |lnr| lnr.protocol }. uniq end |
#exchange_info(vhost, name) ⇒ Object
113 114 115 |
# File 'lib/rabbitmq/http/client.rb', line 113 def exchange_info(vhost, name) decode_resource(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(name)}")) end |
#get_messages(vhost, name, options) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/rabbitmq/http/client.rb', line 159 def (vhost, name, ) response = @connection.post("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/get") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump() end decode_resource_collection(response) end |
#list_bindings(vhost = nil) ⇒ Object
168 169 170 171 172 173 174 175 176 |
# File 'lib/rabbitmq/http/client.rb', line 168 def list_bindings(vhost = nil) path = if vhost.nil? "/api/bindings" else "/api/bindings/#{uri_encode(vhost)}" end decode_resource_collection(@connection.get(path)) end |
#list_bindings_between_queue_and_exchange(vhost, queue, exchange) ⇒ Object
178 179 180 |
# File 'lib/rabbitmq/http/client.rb', line 178 def list_bindings_between_queue_and_exchange(vhost, queue, exchange) decode_resource_collection(@connection.get("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}")) end |
#list_bindings_by_destination(vhost, exchange) ⇒ Object
121 122 123 |
# File 'lib/rabbitmq/http/client.rb', line 121 def list_bindings_by_destination(vhost, exchange) decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/destination")) end |
#list_bindings_by_source(vhost, exchange) ⇒ Object
117 118 119 |
# File 'lib/rabbitmq/http/client.rb', line 117 def list_bindings_by_source(vhost, exchange) decode_resource_collection(@connection.get("/api/exchanges/#{uri_encode(vhost)}/#{uri_encode(exchange)}/bindings/source")) end |
#list_channels ⇒ Object
95 96 97 |
# File 'lib/rabbitmq/http/client.rb', line 95 def list_channels decode_resource_collection(@connection.get("/api/channels")) end |
#list_connections ⇒ Object
83 84 85 |
# File 'lib/rabbitmq/http/client.rb', line 83 def list_connections decode_resource_collection(@connection.get("/api/connections")) end |
#list_definitions ⇒ Object
75 76 77 |
# File 'lib/rabbitmq/http/client.rb', line 75 def list_definitions decode_resource(@connection.get("/api/definitions")) end |
#list_exchanges(vhost = nil) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/rabbitmq/http/client.rb', line 103 def list_exchanges(vhost = nil) path = if vhost.nil? "/api/exchanges" else "/api/exchanges/#{uri_encode(vhost)}" end decode_resource_collection(@connection.get(path)) end |
#list_extensions ⇒ Object
71 72 73 |
# File 'lib/rabbitmq/http/client.rb', line 71 def list_extensions decode_resource_collection(@connection.get("/api/extensions")) end |
#list_nodes ⇒ Object
63 64 65 |
# File 'lib/rabbitmq/http/client.rb', line 63 def list_nodes decode_resource_collection(@connection.get("/api/nodes")) end |
#list_parameters(component = nil) ⇒ Object
315 316 317 318 319 320 321 322 |
# File 'lib/rabbitmq/http/client.rb', line 315 def list_parameters(component = nil) path = if component "/api/parameters/#{uri_encode(component)}" else "/api/parameters" end decode_resource_collection(@connection.get(path)) end |
#list_parameters_of(component, vhost, name = nil) ⇒ Object
324 325 326 327 328 329 330 331 |
# File 'lib/rabbitmq/http/client.rb', line 324 def list_parameters_of(component, vhost, name = nil) path = if name "/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}" else "/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}" end decode_resource_collection(@connection.get(path)) end |
#list_permissions(vhost = nil) ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/rabbitmq/http/client.rb', line 222 def (vhost = nil) path = if vhost "/api/vhosts/#{uri_encode(vhost)}/permissions" else "/api/permissions" end decode_resource_collection(@connection.get(path)) end |
#list_permissions_of(vhost, user) ⇒ Object
232 233 234 |
# File 'lib/rabbitmq/http/client.rb', line 232 def (vhost, user) decode_resource(@connection.get("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}")) end |
#list_policies(vhost = nil) ⇒ Object
281 282 283 284 285 286 287 288 289 |
# File 'lib/rabbitmq/http/client.rb', line 281 def list_policies(vhost = nil) path = if vhost "/api/policies/#{uri_encode(vhost)}" else "/api/policies" end decode_resource_collection(@connection.get(path)) end |
#list_policies_of(vhost, name = nil) ⇒ Object
291 292 293 294 295 296 297 298 |
# File 'lib/rabbitmq/http/client.rb', line 291 def list_policies_of(vhost, name = nil) path = if name "/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}" else "/api/policies/#{uri_encode(vhost)}" end decode_resource_collection(@connection.get(path)) end |
#list_queue_bindings(vhost, queue) ⇒ Object
151 152 153 |
# File 'lib/rabbitmq/http/client.rb', line 151 def list_queue_bindings(vhost, queue) decode_resource_collection(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(queue)}/bindings")) end |
#list_queues(vhost = nil) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/rabbitmq/http/client.rb', line 125 def list_queues(vhost = nil) path = if vhost.nil? "/api/queues" else "/api/queues/#{uri_encode(vhost)}" end decode_resource_collection(@connection.get(path)) end |
#list_users ⇒ Object
250 251 252 |
# File 'lib/rabbitmq/http/client.rb', line 250 def list_users decode_resource_collection(@connection.get("/api/users")) end |
#list_vhosts ⇒ Object
201 202 203 |
# File 'lib/rabbitmq/http/client.rb', line 201 def list_vhosts decode_resource_collection(@connection.get("/api/vhosts")) end |
#node_info(name) ⇒ Object
67 68 69 |
# File 'lib/rabbitmq/http/client.rb', line 67 def node_info(name) decode_resource(@connection.get("/api/nodes/#{uri_encode(name)}")) end |
#overview ⇒ Object
31 32 33 |
# File 'lib/rabbitmq/http/client.rb', line 31 def overview decode_resource(@connection.get("/api/overview")) end |
#protocol_ports ⇒ Hash<String, Integer>
Returns a hash of protocol => port.
58 59 60 61 |
# File 'lib/rabbitmq/http/client.rb', line 58 def protocol_ports self.overview.listeners. reduce(Hash.new) { |acc, lnr| acc[lnr.protocol] = lnr.port; acc } end |
#purge_queue(vhost, name) ⇒ Object
155 156 157 |
# File 'lib/rabbitmq/http/client.rb', line 155 def purge_queue(vhost, name) decode_resource(@connection.delete("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}/contents")) end |
#queue_binding_info(vhost, queue, exchange, properties_key) ⇒ Object
182 183 184 |
# File 'lib/rabbitmq/http/client.rb', line 182 def queue_binding_info(vhost, queue, exchange, properties_key) decode_resource(@connection.get("/api/bindings/#{uri_encode(vhost)}/e/#{uri_encode(exchange)}/q/#{uri_encode(queue)}/#{uri_encode(properties_key)}")) end |
#queue_info(vhost, name) ⇒ Object
135 136 137 |
# File 'lib/rabbitmq/http/client.rb', line 135 def queue_info(vhost, name) decode_resource(@connection.get("/api/queues/#{uri_encode(vhost)}/#{uri_encode(name)}")) end |
#update_parameters_of(component, vhost, name, attributes) ⇒ Object
333 334 335 336 337 338 339 |
# File 'lib/rabbitmq/http/client.rb', line 333 def update_parameters_of(component, vhost, name, attributes) response = @connection.put("/api/parameters/#{uri_encode(component)}/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump(attributes) end decode_resource(response) end |
#update_permissions_of(vhost, user, attributes) ⇒ Object
236 237 238 239 240 241 242 |
# File 'lib/rabbitmq/http/client.rb', line 236 def (vhost, user, attributes) response = @connection.put("/api/permissions/#{uri_encode(vhost)}/#{uri_encode(user)}") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump(attributes) end decode_resource(response) end |
#update_policies_of(vhost, name, attributes) ⇒ Object
300 301 302 303 304 305 306 |
# File 'lib/rabbitmq/http/client.rb', line 300 def update_policies_of(vhost, name, attributes) response = @connection.put("/api/policies/#{uri_encode(vhost)}/#{uri_encode(name)}") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump(attributes) end decode_resource(response) end |
#update_user(name, attributes) ⇒ Object Also known as: create_user
258 259 260 261 262 263 264 |
# File 'lib/rabbitmq/http/client.rb', line 258 def update_user(name, attributes) response = @connection.put("/api/users/#{uri_encode(name)}") do |req| req.headers['Content-Type'] = "application/json" req.body = MultiJson.dump(attributes) end decode_resource(response) end |
#upload_definitions(defs) ⇒ Object
79 80 81 |
# File 'lib/rabbitmq/http/client.rb', line 79 def upload_definitions(defs) raise NotImplementedError.new end |
#user_info(name) ⇒ Object
254 255 256 |
# File 'lib/rabbitmq/http/client.rb', line 254 def user_info(name) decode_resource(@connection.get("/api/users/#{uri_encode(name)}")) end |
#user_permissions(name) ⇒ Object
271 272 273 |
# File 'lib/rabbitmq/http/client.rb', line 271 def (name) decode_resource_collection(@connection.get("/api/users/#{uri_encode(name)}/permissions")) end |
#vhost_info(name) ⇒ Object
205 206 207 |
# File 'lib/rabbitmq/http/client.rb', line 205 def vhost_info(name) decode_resource(@connection.get("/api/vhosts/#{uri_encode(name)}")) end |
#whoami ⇒ Object
275 276 277 |
# File 'lib/rabbitmq/http/client.rb', line 275 def whoami decode_resource(@connection.get("/api/whoami")) end |