ruby-amqp / rabbitmq_http_api_client

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

{bad_header,<<"PUT /api">>} #35

Closed deemytch closed 6 years ago

deemytch commented 6 years ago

archlinux, erlang-nox 20.3.7-1, rabbitmq 3.7.5-1, ruby 2.5.1p57 gems versions after running bundle update

$ grep rabbitmq_http_api_client Gemfile.lock
    rabbitmq_http_api_client (1.9.1)

$ grep faraday Gemfile.lock
    faraday (0.13.1)
    faraday_middleware (0.12.2)
      faraday (>= 0.7.4, < 1.0)
      faraday (~> 0.13.0)
      faraday_middleware (~> 0.12.0)

ruby code

require 'rabbitmq/http/client'
client = RabbitMQ::HTTP::Client.new('http://127.0.0.1:5672', username: 'guest', password: 'guest')
client.create_vhost( 'chat' )
Faraday::ConnectionFailed: Connection reset by peer
from /usr/lib/ruby/2.5.0/socket.rb:452:in `__read_nonblock'

And what in the /var/log/rabbitmq/node.log

2018-06-25 23:50:06.279 [info] <0.13072.0> accepting AMQP connection <0.13072.0> (127.0.0.1:38678 -> 127.0.0.1:5672)
2018-06-25 23:50:06.279 [warning] <0.13072.0> closing AMQP connection <0.13072.0> (127.0.0.1:38678 -> 127.0.0.1:5672):
{bad_header,<<"PUT /api">>}
michaelklishin commented 6 years ago

If you take a closer look at the log lines they mention an "AMQP connection". You are using an HTTP API client which, as the name suggests, uses a different protocol: HTTP.

See the list of protocols and their ports in RabbitMQ documentation and post questions to the ruby-amqp mailing list (or rabbitmq-users) in the future.

michaelklishin commented 6 years ago

The very first example for this library uses a URI with an explicitly specified port.