ruby-amqp / rabbitmq_http_api_client

RabbitMQ HTTP API client for Ruby
MIT License
79 stars 49 forks source link

Unable to update_parameters_of - the server responded with status 400 #23

Closed tetherit closed 9 years ago

tetherit commented 9 years ago

I'm trying to run this:

attributes = { 'uri' => "amqp://test:password@vpn.timeline/monitor", 'reconnect-delay' => 60 }
client.update_parameters_of('federation-upstream', 'monitor', 'Timeline', attributes)

But I'm getting:

Faraday::ClientError: the server responded with status 400
from /var/lib/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response/raise_error.rb:13:in `on_complete'

Any ideas?

michaelklishin commented 9 years ago

The docs have an example with attributes different from yours. Looking at the code I suspect that parameters are expected to be a JSON document (serialised, which the client doesn't do).

tetherit commented 9 years ago

I don't see any examples for federation-upstream on that page, the documentation says this is the format:

PUT /api/parameters/federation-upstream/%2f/my-upstream
{"value":{"uri":"amqp://server-name","expires":3600000}}

You can see some examples here: https://www.rabbitmq.com/federation.html

tetherit commented 9 years ago

Ah, I spotted my mistake! - Here is some working example code for your reference!

def add_federation_upstream(vhost, name, uri)
  attributes = { value: { uri: uri, 'reconnect-delay' => 60 } }
  CLIENT.update_parameters_of('federation-upstream', vhost, name, attributes)
end
michaelklishin commented 9 years ago

@hackeron feel free to add a test that demonstrates how the method is supposed to be used (and cleans up the parameters it defines).

tetherit commented 9 years ago

I am going to sleep soon, but I have added a todo to do this - maybe even add a method add_federation_upstream? - it can take (vhost, name, url, parameters) :)

michaelklishin commented 9 years ago

Sure, take you time.

I'm not opposed adding more specific like put_federation_upstream but we need to have an example for update_parameters_of, even if we use basically the same data in it.