And so here we have a stomp client for ruby, which I found quite easy to use, however quite a few information is available for it.
What you do to use Apache ActiveMQ and the stomp client for ruby?
1, download and install Apache ActiveMQ.
2, download and install rubygems.
3, configure stomp transport in Apache ActiveMQ. In fact, in conf/activemq.xml of your ActiveMQ installation you can see that stomp transport is already configured:
4, writing a message sender using the stomp client for ruby.
#sender.rb
require 'rubygems'
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61613"
client.send('/queue/myqueue',"Hello World!")
client.close
5, writing a message listener using the stomp client for ruby.
#listener.rb
require 'rubygems'
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61613"
client.subscribe "/queue/myqueue" do |message|
puts "received: #{message.body} on #{message.headers['destination']}"
end
client.join
client.close
And so this is it! Just start the ActiveMQ message broker, start the listener (ruby listener.rb), start the sender (ruby sender.rb) and the "Hello World!" message will be transported via ActiveMQ's stomp transport.
1 comment:
thanks for your blogpost, it is was really useful.
I don't know if it is my activeMQ version (5.6.0) or ruby version (1.8) but i found two differences:
1) stomp is not configured by default, I added the line:
2) Also the method is called publish in sender.rb file
client.publish('/queue/myqueue',"Hello World!")
Post a Comment