2012-07-24 15 views
3

我正在使用寶石amqp寶石。我運行了一個AMQP.start事件循環,但在循環過程中'突然it raised a PossibleAuthenticationFailureError`。突然PossibleAuthenticationFailureError in amqp

AMQP.start(amqp_config) do |connection| 
    channel = AMQP::Channel.new connection 
    channel.on_error do |channel, channel_close| 
     puts "Oops... a channel-level exception: code = #{channel_close.reply_code}, message = #{channel_close.reply_text}" 
    end 

    my_worker = MyWorker.new 
    my_worker.start 
    end 

[amqp] Detected TCP connection failure 
/home/raincole/.rvm/gems/ruby-1.9.3-p125/gems/amq-client-0.9.3/lib/amq/client/async/adapters/event_machine.rb:164:in `block in initialize': AMQP broker closed TCP connection before authentication succeeded: this usually means authentication failure due to misconfiguration. Settings are {:host=>"localhost", :port=>5672, :user=>"guest", :pass=>"guest", :vhost=>"/", :timeout=>nil, :logging=>false, :ssl=>false, :broker=>nil, :frame_max=>131072} (AMQP::PossibleAuthenticationFailureError) 

怪異的一部分是,我的工作人員已經收到一些消息之前,我有PossibleAuthenticationFailureError。似乎配置應該是正確的(我一遍又一遍地檢查它)。

PossibleAuthenticationFailureError還有其他可能的原因嗎?

+0

你有沒有想過這個?我看到了同樣的問題。 – Nathan 2013-01-30 19:41:13

回答

8

我推薦一個4步的方法來研究這個問題:

一)消除明顯的 - 是你的憑證正確,是用戶帳戶活得很好(默認爲「客戶」)?你是否連接到適當的虛擬主機(默認='/')?

$ rabbitmqctl list_users 

Listing users ... 
guest [administrator] 
...done. 

$ rabbitmqctl list_user_permissions guest 

Listing permissions for user "guest" ... 
/ .* .* .* 
<your_vhost> .* .* .* 
...done. 


二)什麼的RabbitMQ的連接日誌說?

在Mac OS上安裝rabbitmq(使用brew)時,可以在/ usr/local/var/log/rabbitmq中找到日誌,但根據操作系統和安裝首選項,日誌位置可能在其他地方。

您可能會在[email protected]文件中看到以下行。沒有太多的幫助...所以繼續步驟(c)。否則,請根據您在日誌中看到的內容進行調查。

=INFO REPORT==== 15-Feb-2013::00:42:21 === 
accepting AMQP connection <0.691.0> (127.0.0.1:53108 -> 127.0.0.1:5672) 

=WARNING REPORT==== 15-Feb-2013::00:42:21 === 
closing AMQP connection <0.691.0> (127.0.0.1:53108 -> 127.0.0.1:5672): 
connection_closed_abruptly 


c)是的RabbitMQ的監聽器(二郎客戶端)還活着。默認端口= 5672。最簡單的檢查方法是發送一個垃圾消息到該端口,並尋找一個「AMQP」響應:

$ telnet localhost 5672 
Trying 127.0.0.1... 
Connected to localhost. 
Escape character is '^]'. 
asdasd 
AMQP 
Connection closed by foreign host. 


(d)是對事件循環反應器關閉過早,則AMQP前.connect(或AMQP.start)操作有機會完成身份驗證?

EM.run 
    connection = AMQP.connect(:host => 'localhost', :vhost => '/') do 
    # your code here 
    end 
    EM.stop 
end 

隨着所有'你的代碼'坐在回調中,EM.stop在AMQP.connect指令後立即運行。這沒有時間讓連接適當地建立。

在我這裏工作的是添加一個計時器和處理斷開優雅。

EM.run 
    connection = AMQP.connect(:host => 'localhost', :vhost => '/') 
    # your code here 
    end 

    graceful_exit = Proc.new { 
    connection.close { EM.stop } 
    } 
    EM.add_timer(3, graceful_exit) 
end 

我把EM.stop塊一個Proc的原因是這樣我就可以重新使用它爲其他優雅退出(比如,誘捕「TERM」和「INT」信號時)

希望這幫助。