2013-08-19 36 views
3

我指定稱爲MyQueue的RabbitMQ的服務器上的隊列。它是耐用的,並有x-dead-letter-exchange設置爲MyQueue.DLXAMQP寶石規定成爲一紙空文交換

(我也有一個交換稱爲MyExchange綁定到隊列中,另一交換稱爲MyQueue.DLX,但我不認爲這是問題的重要)

如果我使用Ruby的amqp寶石訂閱者消息我會做這樣的:

# Doing this before and in a new thread has to do with how my code is structured 
# shown here in case it has a bearing on the question 
Thread.new do 
    AMQP.start('amqp://guest:[email protected]:5672') 
end 

EventMachine.next_tick do 
    channel = AMQP::Channel.new(AMQP.connection) 

    queue = channel.queue("MyQueue", :durable => true, :'x-dead-letter-exchange' => "MyQueue.DLX") 

    queue.subscribe(:ack => true) do |metadata, payload| 
    p metadata 
    p payload 
    end 
end 

如果我執行這個代碼隊列,並已創建和綁定交易所(因爲它們需要在我的設置),那麼RabbitMQ的拋出在其日誌中出現以下錯誤:

=ERROR REPORT==== 19-Aug-2013::14:25:53 === 
connection <0.19654.2>, channel 2 - soft error: 
{amqp_error,precondition_failed, 
     "inequivalent arg 'x-dead-letter-exchange'for queue 'MyQueue' in vhost '/': received none but current is the value 'MyQueue.DLX' of type 'longstr'", 
     'queue.declare'} 

這似乎是說,我沒有指定了相同的死信Exchange作爲預先存在的隊列 - 但我相信我與queue = ...線。

任何想法?

+1

因此,如果您沒有任何隊列或交換機聲明,您的代碼是否能夠成功工作? –

+0

如果我宣佈我的隊列沒有死信交換集,那麼是的,它確實有效 - 我認爲這只是我不知道如何用ruby gem指定DLX。 –

回答

3

的DLX信息傳遞在arguments選項:

queue = channel.queue("MyQueue", {durable: true, arguments: {"x-dead-letter-exchange" => "MyQueue.DLX"}}) 
+0

以下是來自同一作者的'bunny'寶石的文檔。 IIRC,它已被棄用贊成'amqp'寶石,但它們非常相似。 https://github.com/ruby-amqp/rubybunny.info/blob/master/articles/extensions.md#dead-letter-exchange-dlx –

0

我有同樣的錯誤,即使使用@Karl威爾伯s格式的選項。

看起來您的RabbitMQ服務器上已經存在「MyQueue」(持久:true),並且它沒有死信交換配置。

queue = channel.queue("MyQueue", :durable => true, :'x-dead-letter-exchange' => "MyQueue.DLX") 

如果名稱「MyQueue」已存在,則不會創建新的隊列。相反,它會嘗試連接到現有的,但選項/參數等必須是相同的,否則你得到一個像你得到的錯誤。

您只需刪除舊的代碼並再次運行您的代碼(使用Karl的建議)。

我用RabbitMQ的管理GUI刪除我的。請參閱here re deleting queues