monitoring an activemq queue with ruby

Thu, Jul 2, 2009

So I have a queue set up as part of a route and I want to monitor what’s going on using a Ruby application. No probs:

First, add a stomp connector to the existing camel config:

<transportConnectors>
  <transportConnector uri=“tcp://localhost:61616” />
  <transportConnector name=“stomp” uri=“stomp://localhost:61613”/>
</transportConnectors>
then write a few lines of Ruby:
# gem install stomp
require ‘stomp’

client = Stomp::Client.open “stomp://localhost:61613”

client.subscribe(“/queue/mqtest.q”) do |msg| msg.headers.each do |header| puts “#{header[0]} = #{header[1]}” end end

client.join

Now, whenever I bung a file into the /tmp/inbound directory, the content is sent to the mqtest.q, Ruby picks it up and shows me the headers:
destination = /queue/mqtest.q
CamelFileAbsolutePath = /tmp/inbound/mqtest-file.txt
CamelFileLength = 16
CamelFileParent = /tmp/inbound
CamelFileLastModified = Thu Jul 02 15:04:12 BST 2009
CamelFileName = mqtest-file.txt
timestamp = 1246543453503
CamelFilePath = /tmp/inbound/mqtest-file.txt
priority = 4
expires = 0
CamelFileCanonicalPath = /private/tmp/inbound/mqtest-file.txt
org_apache_camel_file_name = mqtest-file.txt
message-id = ID:sgarbh.smo.uhi.ac.uk-50846-1246542448854-2:6:1:1:1

comments powered by Disqus