Ruby 指定死信交换的AMQP gem

Ruby 指定死信交换的AMQP gem,ruby,rabbitmq,amqp,Ruby,Rabbitmq,Amqp,我在RabbitMQ服务器上指定了一个名为MyQueue的队列。它经久耐用,并将x-dead-letter-exchange设置为MyQueue.DLX (我还有一个名为MyExchange的交换绑定到该队列,另一个交换名为MyQueue.DLX,但我认为这对这个问题并不重要) 如果我使用ruby的amqpgem订阅这些消息,我会这样做: # Doing this before and in a new thread has to do with how my code is structure

我在RabbitMQ服务器上指定了一个名为
MyQueue
的队列。它经久耐用,并将
x-dead-letter-exchange
设置为
MyQueue.DLX

(我还有一个名为
MyExchange
的交换绑定到该队列,另一个交换名为
MyQueue.DLX
,但我认为这对这个问题并不重要)

如果我使用ruby的
amqp
gem订阅这些消息,我会这样做:

# 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:guest@127.0.0.1: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'}
=错误报告===2013年8月19日::14:25:53===
连接,通道2-软错误:
{amqp_错误,前置条件_失败,
vhost“/”中队列“MyQueue”的不等价arg“x-dead-letter-exchange”:未收到任何内容,但current是类型为“longstr”的值“MyQueue.DLX”,
'队列.声明'}
这似乎意味着我没有指定与先前存在的队列相同的死信交换-但我相信我已经指定了
queue=…


有什么想法吗?

DLX信息通过
参数
选项传递:

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

我也有同样的错误,即使使用@Karl Wilbur的格式作为选项

看起来您的“MyQueue”已经存在于RabbitMQ服务器上(持久:true),并且它的存在没有死信交换配置

queue = channel.queue("MyQueue", :durable => true, :'x-dead-letter-exchange' => "MyQueue.DLX")
如果名为“MyQueue”的队列已经存在,则不会创建新队列。相反,它将尝试连接到现有的一个,但选项/参数等必须相同,否则会出现与您得到的错误相同的错误

您所要做的就是删除旧代码,然后再次运行代码(按照Karl的建议)


我使用RabbitMQ管理GUI删除了我的。请参见

如果您没有声明任何队列或交换,那么您的代码是否能够成功工作?如果我声明队列时没有设置死信交换,那么是的,它确实可以工作-我想只是我不知道如何使用ruby gem指定DLX。以下是来自同一作者的
bunny
gem文档。IIRC,它已被弃用,取而代之的是
amqp
gem,但它们非常相似。