Thursday, May 14, 2009

ActiveMQ, Ruby, STOMP Transport

ActiveMQ is a popular Enterprise Messaging and Integration Patterns provider. ActiveMQ is designed to communicate over a number of protocols (such as Stomp), and it also supports plenty of cross language clients.

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.
require 'rubygems'
require 'stomp'
client = "stomp://localhost:61613"
client.send('/queue/myqueue',"Hello World!")

5, writing a message listener using the stomp client for ruby.
require 'rubygems'
require 'stomp'
client = "stomp://localhost:61613"
client.subscribe "/queue/myqueue" do |message|
puts "received: #{message.body} on #{message.headers['destination']}"

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:

Ijon Tichy said...

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!")

Disqus for Code Impossible