Search code examples
springgrailsjms

JMS request/reply pattern in grails


I am creating a grails web app which makes use of JMS messaging. I have installed the JMS plugin for grails and using activemq as the messaging provider. I want to implement a request/response pattern in grails. I was successfully able to send a message to the queue using the sendQueueJMSMessage("queueName",Map message) from a controller. I then created a service which contains the onMessage() method that listens to the "queueName" as stated above. The onMessage() method does some processing and successfully sends an email to the user. The above scenario has been implemented successfully. Now, I would like to receive a response from this onMessage() method. Lets say I want to implement the below scenario. The request is added to the queue and waits for a response. I looked around but I couldnt find any help. Please give me a lead on this. I really appreciate it.


Solution

  • Spring JMS adds support for auto replies, which the Grails plugin supports. See: http://gpc.github.com/grails-jms/docs/manual/guide/5.%20Receiving%20Messages.html#5.3%20Listener%20Return%20Values

    Here is a test exercising this stuff: https://github.com/gpc/grails-jms/blob/master/test/integration/grails/plugin/jms/test/reply/ReplyingListenerServiceSpec.groovy#L12

    The other option is to just send another message from your first message receiving method.