Skip to content

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

๐Ÿ”ง Terraform Example โ€“ Amazon MQ with ActiveMQ

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

  1. Producer (e.g., Spring Boot app with JMS) connects to ActiveMQ via TCP.

  2. Sends a message to a queue/topic.

  3. Amazon MQ stores the message reliably.

  4. 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