englishteeth.co.uk

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

Grails & JMS Revisited: Topic instead of Queue

Ian | June 26, 2008

Following 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 included much of my post. Right down to the xfire reference, setting up Apache ActiveMQ and my service name typo… Sample was meant to be Simple. Unfortunately no citation, though there was quite a bit of other information added too.

Thomas’ question got me to thinking about publish subscribe as opposed to point to point and how that might be set up using Grails.

No changes were needed to the Apache ActiveMQ set up or the spring configuration in the grails app. I simply added another service to the mix.

class SampleTopicService {
    static expose = ['jms']
    static pubSub = true
    static destination = 'test/topic'

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

}

The destination bit was a little allusive at first. Without it or trying the static “topic” results in the default configuration whereby the service name “sampleTopic” is used for the destination (topic or queue).

To execute this from the grails console needed one extra line to tell the JMS template to use a topic rather than a queue:

def connectionFactory = ctx.getBean("connectionFactory")
def template = new org.springframework.jms.core.JmsTemplate(connectionFactory)
template.setPubSubDomain(true)
template.convertAndSend("test/topic", "Message Posted!")

et voilĂ 
GOT PUBLISHED MESSAGE: Message Posted!

Set the pub sub domain to false and no message is received for SampleTopicService though the previous SampleQueueService works on its destination and visa versa.

Not really the answer to the question Thomas posted here, but it may help with the aspect he mentioned here.

Comments
1 Comment »
Categories
development
Tags
active-mq, grails, jms
Comments rss Comments rss
Trackback Trackback

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.

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 (37)
  • miscellaneous (28)
  • music (7)
  • software (19)

What I'm Doing...

  • If I drink enough to see double will normal TV look 3D? 1 day ago
  • SLF - Here we go! 1 week ago
  • Quite a crowd of media outside Portsmouth's training ground and in the car park opposite this morning. 2 weeks ago
  • 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