englishteeth.co.uk

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

Grails Service, JMS and an MDB

Ian | April 18, 2008

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.

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

« Convention over Configuration This week I have mostly been reading… »

4 responses

It does look simple to do. It pretty much

Thomas Huang | June 25, 2008

It does look simple to do. It pretty much simplified the process of initialize context and JNDI lookups. If the service is to subscribe to a JMS topic that requires user credential, do you know if there is a way to do this?

Hi Thomas, I haven't looked at this much but you'd

Ian | June 26, 2008

Hi Thomas, I haven’t looked at this much but you’d usually provide these credentials to the factory used to create the connections. In this case the connectionFactory bean.

My assumption (which may well be incorrect) was that in my example the connection factory was being used by both sides, producer and consumer. It was just convenient to use it in the groovy script to post the message. Grails can’t be just making that stuff up!

[...] a question onto my post Grails Service, JMS and

englishteeth.co.uk » Grails & JMS Revisited: Topic instead of Queue | June 27, 2008

[...] a question onto my post Grails Service, JMS and an MDB, I was amused and pleased to find that the grails site for the JMS Plugin had been updated and [...]

[...] Grails Service, JMS and an MDB and JMS Plugin

Reiner Saddey’s Place » Grails: Links from my first week with Grails | October 11, 2008

[...] Grails Service, JMS and an MDB and JMS Plugin (e.g. for serving asynchronous requests within an environment that hates new Thread()) [...]

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Author

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

Categories

  • development (37)
  • miscellaneous (28)
  • music (7)
  • software (19)

What I'm Doing...

  • @noelfielding11 why are you in watching telly!? in reply to noelfielding11 2010-04-16
  • What was so good about Nick Drake? These "artists" are covering, music is spot on but no effect at all. Totally lacking the goose pimples. 2010-04-16
  • Some Ginger bloke's on telly covering Nick Drake in a mediocre style. 2010-04-16
  • More updates...

Posting tweet...

Powered by Twitter Tools.

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 css db eclipse esb festivals freesat gorm grails groovy hd hibernate htpc 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 vmc web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox