movitto / rjr

Ruby JSON-RPC Library - json-rpc server/client mechanisms over amqp, websockets, and other transports, written in ruby
Apache License 2.0
68 stars 9 forks source link

Readme/examples should demonstrate AMQP connection with username/password #9

Open gregkrsak opened 10 years ago

gregkrsak commented 10 years ago

Currently, the README.md and examples only show an AMQP connection that appears to be using the default guest account. Could we get more info on how rjr operates with respect to opening connections that require credentials? If I re-create the guest account, my connection works just fine.

gregkrsak commented 10 years ago

irb(main):003:0> puts amqp_node.invoke('gmk-dev-queue', 'hello', 'world')

Critical exception AMQP broker closed TCP connection before authentication succeeded: 
this usually means authentication failure due to misconfiguration. Settings are 
{:host=>"192.168.2.7", :port=>5672, :user=>"guest", :pass=>"[filtered]", 
:auth_mechanism=>"PLAIN", :vhost=>"/", :timeout=>nil, :logging=>false, :ssl=>false,
:frame_max=>131072, :heartbeat=>0}
/Library/Ruby/Gems/2.0.0/gems/amqp-1.3.0/lib/amqp/session.rb:187:in `block in initialize'
/Library/Ruby/Gems/2.0.0/gems/amqp-1.3.0/lib/amqp/session.rb:646:in `call'
/Library/Ruby/Gems/2.0.0/gems/amqp-1.3.0/lib/amqp/session.rb:646:in `unbind'
/Library/Ruby/Gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:1438:in `event_callback'
/Library/Ruby/Gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
/Library/Ruby/Gems/2.0.0/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
/Library/Ruby/Gems/2.0.0/gems/rjr-0.18.2/lib/rjr/em_adapter.rb:34:in `block (2 levels) in start'
movitto commented 10 years ago

@gregkrsak hey thanks for reaching out.

Admittedly I restrict access to my broker to localhost only so auth at that level isn't as pressing of a concern but it should be able to be easily incorporated.

The current RJR::Nodes::AMQP initialization will need to be expanded though to accept the username and password to use when connecting to the broker:

https://github.com/movitto/rjr/blob/master/lib/rjr/nodes/amqp.rb#L117

Upon initialization we can pass these credentials onto the ruby-amqp gem which rjr is using on the backend:

https://github.com/movitto/rjr/blob/master/lib/rjr/nodes/amqp.rb#L65 http://rubyamqp.info/articles/connecting_to_broker/

movitto commented 10 years ago

Hey not 100% sure when I'll be able to get to this (have a bunch of high priority items on various backlogs for the next month or two) but created the issue to track it. Of course if you want to see this in sooner feel free to send a PR! :-)

Again thanks for the issue, -Mo