Mocking SQS with ElasticMQ and docker-compose

Giovanni Lela
LinkMe
Published in
2 min readDec 6, 2017

--

Amazon Simple Queue Service is a simple and cost effective message queue. It is also completely managed, and that’s cool … except for the inconvenience of having to create and mantain queues for each development / integration environment. As this is extra boring, I tried to find out if there is a way to reliably mock SQS queues, and I found ElasticMQ, a simple queue system written in Scala exposing an SQS compatible REST interface. Note that it does not yet support FIFO queues: if you are searching for a way to mock them, then this is not the right place to look at — sorry!

As I am a quite a huge fan of docker-compose development environments, here wel’ll integrate an elasticMQ service into a docker-compose environment.

First of all let’s add an elasticMQ service in the docker-compose.yml file. We’ll be using this docker image https://hub.docker.com/r/s12v/elasticmq/~/dockerfile/

services:
queue:
image: s12v/elasticmq
ports:
- "9324:9324"

Done! Enjoy your queue on port 9324! Happy messaging!
Not so fast, we are still not done here: as we are most likely using elasticMQ for testing, we also do not want to manually create our queues. We can provide a config file describing the queues we want to be in place:

// this is mostly copy pasted from elasticMQ's README.md
include classpath("application.conf")
// What is the outside visible address of this ElasticMQ node
// Used to create the queue URL (may be different from bind address!)
node-address {
protocol = http
host = localhost
port = 9324
context-path = ""
}
rest-sqs {
enabled = true
bind-port = 9324
bind-hostname = "0.0.0.0"
// Possible values: relaxed, strict
sqs-limits = strict
}
// Should the node-address be generated from the bind port/hostname
// Set this to true e.g. when assigning port automatically by using port 0.
generate-node-address = false
queues {
queue1{
defaultVisibilityTimeout = 10 seconds
delay = 5 seconds
receiveMessageWait = 0 seconds
deadLettersQueue {
name = "queue1-dead-letters"
maxReceiveCount = 3 // from 1 to 1000
}
}
queue1-dead-letters{ }
queue2 {
defaultVisibilityTimeout = 10 seconds
delay = 5 seconds
receiveMessageWait = 0 seconds
deadLettersQueue {
name = "queue2-dead-letters"
maxReceiveCount = 3 // from 1 to 1000
}
}
queue2-dead-letters{ }
}

Then we’ll just have to mount the file in the container, so we’ll update our docker-compose.yml like this:

services:
queue:
image: s12v/elasticmq
volumes:
- ./path/to/custom.conf:/etc/elasticmq/elasticmq.conf
ports:
- "9324:9324"

Now when we’ll docker-compose up we’ll have two queues with their own dead letter queue.. nice :)

--

--