VOOZH about

URL: https://www.javacodegeeks.com/2018/07/migrate-elastic-beanstalk-docker.html

⇱ Migrate your elastic beanstalk workers to docker containers - Java Code Geeks


Amazon Elastic Beanstalk is one of the most popular services that aws provides. Elastic beanstalk comes with two options, the worker and the web application.

The worker application consumes the messages from a sqs queue and process them. If the process was successful the message is removed from the queue, if not the message shall remain in the queue or after some failed attempts it will go back to a dead letter queue. If you want to get more into elb I have made a tutorial on deploying you spring application using elb and cloudformation.

👁 elastic beanstalk

Elastic beanstalk workers are really great because they are managed, they can be scaled up/down depending on your workloads and they provide a wide variety of development environments like java, node.js and also you can use docker images.

Although elastic bean can work wonders if you have an aws based infrastructure you might face some issues when you will try to move to a container based infrastructure using a container orchestration engine.

👁 elastic beanstalk

Most probably your containerized worker application will work seamlessly without any extra configuration, however you need to find an alternative for the agent which dispatches the queue messages to your application.

In order to make things simple I implemented a mechanism which retrieves the messages from the queue and sends them to the worker application.

The container-queue-worker projects aims to provide an easy way to migrate your elastic beanstalk workers to a docker orchestration system.

Since the solution is Scala based it can either be used as a standalone jvm application or it can be run in a container using the image from dockerhub.

Once set up what you need to add the routing configurations.

This can be done using environmental variables

WORKER_TYPE=sqs
WORKER_SERVER_ENDPOINT=http://{docker-service}
WORKER_AWS_QUEUE_ENDPOINT=http://{amazon queue endpoint}

Or if you use it as a container you can add a config file on the /etc/worker/worker.conf path.

worker {
 type = sqs
 server-endpoint = http://{docker-service}
 aws {
 queue-endpoint = http://{amazon queue endpoint}
 }
}

In order to make thing easier for you I added a docker compose file simulating the desired outcome.

version: '3.5'
networks:
 queue-worker-network:
 name: queue-worker-network
services:
 worker-server:
 build:
 context: ./worker-server
 dockerfile: Dockerfile
 ports:
 - 8080:8080
 networks:
 - queue-worker-network
 elasticmq:
 build:
 context: ./elasticmq
 dockerfile: Dockerfile
 ports:
 - 9324:9324
 networks:
 - queue-worker-network
 container-queue-worker:
 image: gkatzioura/container-queue-worker:0.1
 depends_on:
 - elasticmq
 - worker-server
 environment:
 WORKER_TYPE: sqs
 WORKER_SERVER_ENDPOINT: http://worker-server:8080/
 WORKER_AWS_QUEUE_ENDPOINT: http://elasticmq:9324/queue/test-queue
 AWS_DEFAULT_REGION: eu-west-1
 AWS_ACCESS_KEY_ID: access-key
 AWS_SECRET_ACCESS_KEY: secret-key
 networks:
 - queue-worker-network
Published on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Migrate your elastic beanstalk workers to docker containers

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Emmanouil Gkatziouras
Emmanouil Gkatziouras
July 16th, 2018Last Updated: July 16th, 2018
0 149 2 minutes read

Emmanouil Gkatziouras

He is a versatile software engineer with experience in a wide variety of applications/services.He is enthusiastic about new projects, embracing new technologies, and getting to know people in the field of software.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz