我试图获得基本的交换=>排队等待兔子。
http://localhost:15672/
我启动了消息发送器:
http://localhost:15672/#/exchanges/%2F/yomtvraps
......然而在#34;消息率崩溃" 有0条消息传出(" ...没有发布...")
队列什么都没有收到:
http://localhost:15672/#/queues/%2F/yomtvraps
我在这里缺少什么? 我猜在交换和队列之间没有设置好的东西。但是什么?
答案 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!