AWS — RabbitMQ Consumers — Lambda Vs EC2 Vs ECS

Akshay Malik
3 min readAug 28, 2020

--

First of all, let's talk about what is RabbitMQ

RabbitMQ is a modern Messaging Broker built on the new AMQP protocol and championed by Pivotal. It offers many advantages over older messaging systems such as JMS (IMHO) and is gaining in popularity.

We now understand what are consumers in RabbitMQ world

The term “consumer” means different things in different contexts. In general in messaging a consumer is an application (or application instance) that consumes messages. The same application can also publish messages and thus be a publisher at the same time.

In this sense, a consumer is a subscription for message delivery that has to be registered before deliveries begin and can be cancelled by the application.

Producer and Consumer

AWS Lambda as Consumer for RabbitMQ

AWS Lambda can be used as a consumer for RabbitMQ but only in certain conditions that should be known before making any design decisions.

Lambda polling from RabbitMQ to store data in DynamoDB

When to use AWS Lambda?

  • Continuous polling is not required since lambda will wake up only on cloud watch events.
  • A large number of messages are not expected.
  • Polling can only be done for a fixed set of messages depending on the logic that needs to be performed.

AWS ECS as Consumer for RabbitMQ

AWS ECS can be used as a consumer for RabbitMQ which will be a favorable option if you like the Managed option rather than deploying the same app in an EC2 and worry around managing the instance.

ECS polling RabbitMQ

When to use AWS ECS?

  • Continous polling is required since lambda can only work for the max time it is configured to run.
  • A large number of messages are expected.
  • Continous polling will be done where consumers/messages to fetch/concurrency can be all configured by a simple configuration.
  • Managing infrastructure is a problem.
  • Auto-scaling can be achieved by a simple scaling plan to scale up and down the instances acting as consumers.

AWS EC2 as Consumer for RabbitMQ

AWS EC2 can be used with all the possible reasons ECS can be used as a consumer but EC2 is not a managed option. If managing infrastructure is not a problem, then EC2 otherwise ECS which gives you the luxury to be connected to the queue for long polling in a “Managed” way.

Next article we will look at how we can create a simple spring boot application with docker to be used with ECS to be a consumer for RabbitMQ.

--

--

Akshay Malik

5X AWS Certified | 5+ Serverless Applications | Cloud Architectures | Commerce Architectures | DevOps | Microservices | Docker | @profile.acloudcoder.com