Question

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
Était-ce utile?

La 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.

Autres conseils

Although client.join did successfully pull down the first message or two for me, after it ran, the code completely stopped working, and the subscriber would simply hang again. I was starting my client in a very similar way (just lacking creds):

client = Stomp::Client.new('localhost', 61613)

But I was able to get it working by using a URL instead:

client = Stomp::Client.new('stomp://localhost:61613')

With creds, it would look something like:

client = Stomp::Client.new('stomp://login:passcode@host:port')

Hope this helps the next person with this issue.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top