englishteeth.co.uk

… the weblog of Ian “English Teeth” Robinson
  • rss
  • Home

Grails Service, JMS and an MDB

April 18, 2008 | 1:01 pm

After I sort of set a challenge when thinking about Convention over Configuration, I had to see if it was in fact doable in a framework that exploits the principals.

This was straight from the grails site for the JMS Plugin, but in less than 30 minutes I have an exposed message driven bean receiving a JMS message and that includes downloading the plug-in and Apache ActiveMQ.

As I say, I had to go to download the plugin since, due to what I think is a proxy issue, I couldn’t directly use grails install-plugin jms

Though the following worked fine enough
grails install-plugin C:\Local\downloads\grails-jms-0.3.zip

I needed to copy over three libraries from the ActiveMQ distribution and add a little bit of Spring

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id = "connectionFactory" class = "org.apache.activemq.ActiveMQConnectionFactory">
        <property name = "brokerURL" value = "tcp://localhost:61616"/>
    </bean>
</beans>

I then added the service (much like the xfire one) to receive messages (the message driven bean).

class SampleQueueService {
    static expose = ['jms']

    def onMessage(messageObject) {
       println "GOT MESSAGE: $messageObject"
    }

}

Then it was just a matter of running the grails console and entering three lines to send a messge:

def connectionFactory = ctx.getBean("connectionFactory")
def template = new org.springframework.jms.core.JmsTemplate(connectionFactory)
template.convertAndSend("sampleQueue", "Message Posted!")

et voilĂ 
GOT MESSAGE: Message Posted!
I may be easily pleased, but I found that quite satisfying.

Comments
4 Comments »
Categories
development
Tags
active-mq, grails, jms, mdb
Comments rss Comments rss
Trackback Trackback

Author

Ian Robinson is a relatively agile software engineer interested in things both sides of the object relational divide and beyond.

Categories

  • development (35)
  • miscellaneous (20)
  • music (7)
  • software (13)

Blogroll

  • Dan North
  • Dave Astels
  • Dave Wood
  • eirikso.com
  • Matt Raible
  • Object Mentor Blog
  • The Ancient Art of Programming
  • The Wisdom of Ganesh

Tags

active-mq architecture bauhaus blu-ray css db eclipse esb festivals freesat gorm grails groovy hd hd-dvd hibernate java jboss jms junit links mce media center mini music oracle osgi patterns pirsig plugins satellite soa software spring sql struts2 testing themes tools tv web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox