The avenue in mist and sun

Originally uploaded by algo

Spring JMS has made JMS easy. JRuby makes it even easier.

I have used the OpenAdaptor as JMS clients for benchmarking and supporting tasks. With many ready-built components I can do most of things I need to do, but sometimes I can’t do simple things like sending a sample message in a file repeatedly for benchmarking unless I do a bit of java programming to extend the existing components.

The Spring’s SimpleMessageContrainer works well as a simple subscriber like for benchmarking or draining messages. I just needed to set the AutoStartup to false and set a JRuby implementation of the MessageListener to the SimpleMessageContainer bean programmatically before starting it up.

However, the JmsTemplate falls short on the publishing side, i.e. it opens and closes a session every time it sends a message. James Strachan has more on that. So I needed to create a session and a publisher in JRuby. Even so, it’s still easy as the Spring does the rest.

OpenAdaptor’s JMS Peek utility is useful as a diagnostic aid especially for Topic as it does not have a browsing interface like QueueBrowser. There were a few support cases in the past where users wanted to peek more than one messages. Not surprisingly, it was easily done in JRuby with Spring JMS. Fisrt, I tried to set the SessionAcknowledgeMode of SimpleMessageContainer to CLIENT_ACKNOWLEDGE, but it turned out that the SimpleMessageContainer called acknowledge() on Message. So, like the JRuby publisher, I have created a durable subscriber to receive a number of messages without acknowledging them.

Here are source codes of the above JRuby scripts. They are good enough to get simple things done quickly and simply. That’s why I love JRuby.

Related Posts: