hello world!
Published: March 31, 2013

Amazon Web Services SQS in Grails with Spring JMS

I recently needed a quick and simple queue implementation for a Grails project but didn't want the hassle of maintaining an extra application like ApacheMQ or RabbitMQ.

Since this Grails project was already to be housed in Amazon EC2 I decided to pursue the use of AWS's SQS (Simple Queue Service).

Although some Grails SQS plugins already existed, none provided the ease of functionality that the ApacheMQ and the Grails JMS plugin would.

After a little internet research, I came across the Nevado JMS library that included a Spring JMS Provider for AWS SQS.

Once wired it up, it worked perfectly.

I started by including the required dependencies in my grails-app/conf/BuildConfig.groovy

dependencies {
    compile 'com.amazonaws:aws-java-sdk:1.4.1'
    compile 'org.skyscreamer:nevado-jms:1.1.1'
plugins {
    compile ":jms:1.2"

And then configured the Nevado JMS Provider in my grails-app/conf/spring/resources.groovy

beans = {
    ) {
         sqsConnectorFactory = ref(sqsConnectorFactory)
         awsAccessKey = "YOUR_AWS_ACCESS_KEY"
         awsSecretKey = "YOUR_AWS_SECRET_KEY"

That's about all the configuration there is.

You can then send messages using the JmsService...

import grails.plugin.jms.*

class SomeService {
    static exposes = ["jms"]
    JmsService jmsService
    String SQS_QUEUE_NAME = 'mySqsQueue'

    def sendMessage() {
        jmsService.send SQS_QUEUE_NAME, "This is my message!"

    def mySqsListener(msg) {
        println msg

The mySqsLister() is always listening to SQS for new messages.

One comment on “Amazon Web Services SQS in Grails with Spring JMS”

  1. Thanks Bryan, this was a big help. Thought I'd mention that for me it was necesssary to add the jms api jar to my local maven cache after updating BuildConfig.groovy. This prevented a javax.jms.MessageListener class not found exception when building locally. In case anyone else runs into this, the jms.jar can be had from http://www.oracle.com/technetwork/java/javaee/downloads/index.html. I added it to the local repository using something the following.

    mvn install:install-file -Dfile=jms.jar -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar

Leave a Reply