質問

I'm trying to get a basic exchange => queue going on rabbitmq.

  • I have my localhost running rabbitmq
  • the rabbitmq web dashboard is available at http://localhost:15672/
  • I have a message source (logstash) writing to an exchange called "yomtvraps"
  • I have a queue called "yomtvraps"
  • I have a binding from the exchange "yomtvraps" to the queue "yomtvraps" that shows up on the details page of both the exchange and the queue

I start my message emitter:

  • the web page showing all the exchanges shows incoming messages at a rate of 80/s
  • the exchange page shows a graph with the incoming messages http://localhost:15672/#/exchanges/%2F/yomtvraps

...yet under "Message rates breakdown" there are 0 messages Outgoing ("... no publishes ...")

The queue receives nothing:

  • the receiver I have listening never gets any messages
  • the queue page shows no incoming messages http://localhost:15672/#/queues/%2F/yomtvraps

What am I missing here? I guess there's something not set right between the exchange and the queue. But what?

役に立ちましたか?

解決

The problem is basically: the routing key was unset for both, and apparently the exchange and queue needed that key.

the sender:

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

the receiver:

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

The output (in two different terminals):

$ 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!
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top