Search code examples
rubyactivemq-classicstomp

ActiveMQ with Ruby Stomp gem - subscribing fails


New to ActiveMQ. Using ruby stomp gem. I believe I'm successfully publish'ing messages to the server, as I see them in the queue in my browser admin client. But on subscribe nothing happens, no error, no output. The "in subscribe" test text from puts never appears in stdout, nor does the msg.

Should I be using a different naming format for the queues?

require 'stomp'
port = 61613

client = Stomp::Client.new( 'admin', 'admin', '127.0.0.1', port )
client.publish("/queue/mine2", "hello world!")
puts "about to subscribe"

client.subscribe("/queue/mine2") do |msg|
  puts "in subscribe"
  puts msg
end
client.close

Solution

  • I believe You are closing the client before it gets a chance to receive anything.

    If there is no preemption between client.subscribe and client.close background thread that listens for new messages never gets run.

    You should try adding

    client.join
    

    before closing it.