Active MQ
๐จ What is Amazon MQ?
Amazon MQ is a managed message broker service for Apache ActiveMQ and RabbitMQ that makes it easy to set up and operate messaging systems in the cloud without managing infrastructure.
โ
Use it when migrating existing message-based applications that rely on standard protocols like AMQP, MQTT, STOMP, OpenWire, JMS, or WebSocket.
๐ง Key Concepts
| Concept |
Description |
| Message Broker |
Software that enables apps to communicate via queues and topics asynchronously |
| Amazon MQ Broker |
A fully managed ActiveMQ or RabbitMQ instance |
| Queue / Topic |
Destination type where messages are delivered (point-to-point or publish-subscribe) |
| Persistent Storage |
Messages are stored until consumed |
| Security Groups |
Control access to the broker endpoint |
๐ Supported Engines
| Engine |
Description |
| ActiveMQ |
Ideal for traditional JMS apps, supports durable queues/topics, transactions |
| RabbitMQ |
More lightweight, plugin-friendly, widely used in microservices |
๐ ๏ธ Common Use Cases
| Use Case |
Why Amazon MQ? |
| ๐งณ Legacy enterprise migration |
Lift-and-shift existing JMS/RabbitMQ apps |
| ๐ Application decoupling |
Queues and topics help microservices communicate |
| ๐ Publish-subscribe workflows |
Topics with multiple subscribers |
| ๐ Reliable inter-service comms |
Persistent, ordered, guaranteed delivery |
๐งฐ Amazon MQ vs Alternatives
| Feature |
Amazon MQ |
SQS |
Kinesis |
| Protocol Support |
AMQP, MQTT, JMS, STOMP, etc. |
AWS SDK only |
AWS SDK only |
| Message Size |
Up to 100 MB |
256 KB max |
1 MB |
| Ordering |
FIFO |
FIFO queue available |
Per partition key |
| Retention |
Until acknowledged |
Configurable (up to 14 days) |
24hโ7d |
| Best for |
Legacy MQ apps |
Event queueing, background jobs |
Stream processing |
๐ Security Features
| Feature |
Support |
| IAM for API |
โ
Create/delete brokers |
| VPC |
โ
Deployed within your private subnets |
| TLS Encryption |
โ
TLS enforced endpoints |
| Authentication |
โ
Basic Auth (user/password) |
| Logging |
โ
CloudWatch logs for broker events |
| KMS Encryption |
โ
Optional for message storage |
1. Create a Security Group for the Broker
resource "aws_security_group" "mq_sg" {
name = "amazon-mq-sg"
description = "Allow access to MQ"
vpc_id = "vpc-xxxxxxxx" # replace with your VPC ID
ingress {
protocol = "tcp"
from_port = 61617
to_port = 61617
cidr_blocks = ["10.0.0.0/16"] # limit to app subnets
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
2. Create the Amazon MQ Broker (ActiveMQ)
resource "aws_mq_broker" "mq" {
broker_name = "my-activemq-broker"
engine_type = "ActiveMQ"
engine_version = "5.17.6" # or latest
deployment_mode = "SINGLE_INSTANCE"
host_instance_type = "mq.t3.micro"
publicly_accessible = false
security_groups = [aws_security_group.mq_sg.id]
subnet_ids = ["subnet-xxxxxx"] # Replace with your private subnet
user {
username = "admin"
password = "YourStrongPassword123!" # Store securely with TF vars
}
logs {
general = true
}
maintenance_window_start_time {
day_of_week = "Monday"
time_of_day = "02:00"
time_zone = "UTC"
}
}
๐ Monitoring with CloudWatch
| Metric |
Description |
CurrentConnections |
Active client connections |
QueueSize |
Messages in a queue |
StorePercentUsage |
Broker disk utilization |
MemoryPercentUsage |
Heap usage (especially for ActiveMQ) |
EnqueueCount |
Number of messages added to queue/topic |
๐งช Message Flow Example
-
Producer (e.g., Spring Boot app with JMS) connects to ActiveMQ via TCP.
-
Sends a message to a queue/topic.
-
Amazon MQ stores the message reliably.
-
Consumer retrieves and processes the message.
๐ง Connecting App to Amazon MQ (Java Example)
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
"ssl://b-xxx.mq.us-east-1.amazonaws.com:61617"
);
factory.setUserName("admin");
factory.setPassword("YourStrongPassword123!");
Connection connection = factory.createConnection();
๐ฐ Pricing (as of 2024)
| Resource |
Cost |
| Broker Instance (t3.micro) |
~~$0.04/hour (~~$30/month) |
| Storage |
$0.10/GB/month |
| Data Transfer |
Free inbound, standard outbound rates apply |
| No charge for idle |
โ Charges apply even if no messages |
โ
TL;DR Summary
| Feature |
Amazon MQ |
| Managed Message Broker |
โ
Supports ActiveMQ and RabbitMQ |
| Use case |
Legacy JMS apps, enterprise queuing, pub-sub |
| Protocols |
AMQP, STOMP, MQTT, JMS, OpenWire, WebSocket |
| Message Durability |
โ
Persistent + durable |
| Autoscaling |
โ Manual sizing (via instance type) |
| Terraform Support |
โ
aws_mq_broker, aws_security_group |