rabbitmq exchange永远不会发布到队列绑定

时间:2014-04-23 21:05:57

标签: ruby rabbitmq

我试图获得基本的交换=>排队等待兔子。

  • 我的localhost运行了rabbitmq
  • rabbitmq网络信息中心位于http://localhost:15672/
  • 我有一个消息来源(logstash)写一个名为" yomtvraps"
  • 的交易所
  • 我有一个名为" yomtvraps"
  • 的队列
  • 我有来自交易所的约束" yomtvraps"到队列" yomtvraps"显示在交换和队列的详细信息页面上

我启动了消息发送器

  • 显示所有交易所的网页以80 / s的速率显示收到的消息
  • 交换页面显示包含传入消息http://localhost:15672/#/exchanges/%2F/yomtvraps
  • 的图表

......然而在#34;消息率崩溃" 有0条消息传出(" ...没有发布...")

队列什么都没有收到

  • 我听的接收器永远不会收到任何消息
  • 队列页面显示没有传入消息http://localhost:15672/#/queues/%2F/yomtvraps

我在这里缺少什么? 我猜在交换和队列之间没有设置好的东西。但是什么?

1 个答案:

答案 0 :(得分:0)

问题基本上是:两者都没有设置路由密钥,显然交换和队列需要该密钥。

发件人:

require "bunny"

NAME_OF_QUEUE = "yomtvraps"
NAME_OF_EXCHANGE = "yomtvraps"

conn = Bunny.new(:automatically_recover => false)
conn.start

ch   = conn.create_channel
q    = ch.queue("yomtvraps")

puts "\tthere was already a queue named \"#{NAME_OF_QUEUE}\"" if conn.queue_exists?(NAME_OF_QUEUE)
puts "\tthere was already a exchange named \"#{NAME_OF_EXCHANGE}\"" if conn.exchange_exists?(NAME_OF_EXCHANGE)

exchange    = ch.direct(NAME_OF_EXCHANGE, :durable => true)

exchange.publish("Hello World!", :routing_key => NAME_OF_QUEUE)
puts " [x] Sent 'Hello World!'"

conn.close

接收者:

require "bunny"

NAME_OF_QUEUE = "yomtvraps"
NAME_OF_EXCHANGE = "yomtvraps"

conn = Bunny.new(:automatically_recover => false)
conn.start

ch   = conn.create_channel
q    = ch.queue(NAME_OF_QUEUE)

exchange    = ch.direct(NAME_OF_EXCHANGE, :durable => true)  # this is how logstash

begin
  puts " [*] Waiting for messages. To exit press CTRL+C"
  q.bind(exchange, :routing_key => NAME_OF_QUEUE).subscribe(:block => true) do |delivery_info, properties, body|
    puts " [x] Received #{body}"
  end
rescue Interrupt => _
  conn.close

  exit(0)
end

输出(在两个不同的终端):

$ ruby send_exchange.rb
    there was already a queue named "yomtvraps"
    there was already a exchange named "yomtvraps"
 [x] Sent 'Hello World!'

$ ruby receive_queue.rb
 [*] Waiting for messages. To exit press CTRL+C
 [x] Received Hello World!