AWS Learning
Messaging & Streaming

Amazon MQ

Managed ActiveMQ/RabbitMQ, Migration từ on-premises

Tổng quan

Amazon MQ là managed message broker service hỗ trợ Apache ActiveMQRabbitMQ. Dành cho việc migrate từ on-premises messaging systems sang AWS mà không cần thay đổi code.

┌─────────────────────────────────────────────────────────────────┐
│                    WHY AMAZON MQ?                               │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   On-Premises                              AWS                  │
│   ┌──────────────┐                    ┌──────────────┐          │
│   │  ActiveMQ /  │                    │  SQS + SNS   │          │
│   │  RabbitMQ /  │  ──Migrate to──→   │              │          │
│   │  IBM MQ      │                    │  (Cloud-     │          │
│   │              │                    │   native)    │          │
│   └──────────────┘                    └──────────────┘          │
│         │                                   │                   │
│         │  ❌ Requires code changes         │                   │
│         │  ❌ Different APIs                │                   │
│         │                                   │                   │
│         ↓                                   │                   │
│   ┌──────────────┐                          │                   │
│   │  Amazon MQ   │ ←── OR migrate to ──────┘                    │
│   │  (Managed     │                                             │
│   │   Broker)     │                                             │
│   └──────────────┘                                              │
│         │                                                       │
│         ✅ Same APIs (AMQP, MQTT, OpenWire, STOMP)              │
│         ✅ No code changes needed                               │
│         ✅ Managed by AWS                                       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Khi nào dùng Amazon MQ vs SQS/SNS?

ScenarioRecommend
New cloud-native appSQS + SNS
Migrate existing apps using standard protocolsAmazon MQ
Need AMQP, MQTT, STOMP, OpenWireAmazon MQ
Serverless, auto-scalingSQS + SNS
Maximum throughput, unlimited scaleSQS + SNS

  1. Broker Engines
  2. Architecture
  3. Deployment Modes
  4. Protocols & Features
  5. Security
  6. So sánh SQS/SNS vs Amazon MQ
  7. Best Practices

1. Broker Engines

1.1 Apache ActiveMQ

┌─────────────────────────────────────────────────────────────────┐
│                    APACHE ACTIVEMQ                              │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Features:                                                     │
│   • Queue và Topic support                                      │
│   • Multiple protocols: OpenWire, STOMP, AMQP, MQTT             │
│   • Mature, widely used                                         │
│   • Complex routing patterns                                    │
│                                                                 │
│   Instance Types:                                               │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │  mq.t3.micro   → Dev/Test (cheaper)                     │   │
│   │  mq.m5.large   → Production                             │   │
│   │  mq.m5.xlarge  → High throughput                        │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   Storage:                                                      │
│   • EFS (shared storage for HA)                                 │
│   • EBS (single instance)                                       │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

1.2 RabbitMQ

┌─────────────────────────────────────────────────────────────────┐
│                      RABBITMQ                                   │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Features:                                                     │
│   • AMQP 0-9-1 protocol                                         │
│   • Advanced routing (exchanges, bindings)                      │
│   • Lightweight, fast                                           │
│   • Plugin ecosystem                                            │
│                                                                 │
│   Key Concepts:                                                 │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                                                         │   │
│   │   Producer → Exchange → Binding → Queue → Consumer      │   │
│   │                                                         │   │
│   │   Exchange Types:                                       │   │
│   │   • Direct   → Route by exact routing key               │   │
│   │   • Topic    → Route by pattern matching                │   │
│   │   • Fanout   → Broadcast to all queues                  │   │
│   │   • Headers  → Route by message headers                 │   │
│   │                                                         │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   Storage: EBS only (faster but not shared)                     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

1.3 ActiveMQ vs RabbitMQ

FeatureActiveMQRabbitMQ
ProtocolsOpenWire, STOMP, AMQP, MQTTAMQP 0-9-1
RoutingBasicAdvanced (Exchanges)
HA StorageEFS (shared)Cluster replication
Management UIWeb consoleManagement plugin
Use CaseJMS-based Java appsModern microservices

2. Architecture

2.1 Single-Instance Broker

┌──────────────────────────────────────────────────────────────────┐
│                  SINGLE-INSTANCE BROKER                          │
├──────────────────────────────────────────────────────────────────┤
│                                                                  │
│   ┌──────────────────────────────────────────────────────┐       │
│   │                   Single AZ                          │       │
│   │  ┌─────────────────────────────────────────────┐       │     │
│   │  │              Amazon MQ Broker               │       │     │
│   │  │                                             │       │     │
│   │  │   ┌─────────────┐    ┌─────────────┐        │       │     │
│   │  │   │   ActiveMQ  │ or │  RabbitMQ   │        │       │     │
│   │  │   │   Instance  │    │  Instance   │        │       │     │
│   │  │   └──────┬──────┘    └──────┬──────┘        │       │     │
│   │  │          │                  │               │       │     │
│   │  │          ↓                  ↓               │       │     │
│   │  │   ┌─────────────────────────────────┐       │       │     │
│   │  │   │          EBS Storage            │       │       │     │
│   │  │   └─────────────────────────────────┘       │       │     │
│   │  └─────────────────────────────────────────────┘       │     │
│   └──────────────────────────────────────────────────────┘       │
│                                                                  │
│   ⚠️  Not recommended for production (no failover)               │
│   ✅ Good for development/testing                                │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

2.2 Active/Standby Broker (ActiveMQ)

┌─────────────────────────────────────────────────────────────────┐
│              ACTIVE/STANDBY (HIGH AVAILABILITY)                 │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   ┌─────────────────────┐    ┌─────────────────────┐            │
│   │     AZ 1            │    │     AZ 2             │           │
│   │  ┌───────────────┐  │    │  ┌───────────────┐   │           │
│   │  │    ACTIVE     │  │    │  │   STANDBY     │   │           │
│   │  │   (Running)   │  │    │  │  (Waiting)    │   │           │
│   │  └───────┬───────┘  │    │  └───────┬───────┘   │           │
│   └──────────│──────────┘    └──────────│──────────┘            │
│              │                          │                       │
│              └──────────┬───────────────┘                       │
│                         ↓                                       │
│              ┌─────────────────────────┐                        │
│              │   Amazon EFS (shared)   │                        │
│              │   Message Storage       │                        │
│              └─────────────────────────┘                        │
│                                                                 │
│   Failover:                                                     │
│   • Active fails → Standby takes over (1-2 minutes)             │
│   • Same DNS endpoint, transparent to clients                   │
│   • Messages persisted in EFS                                   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

2.3 Cluster Deployment (RabbitMQ)

┌─────────────────────────────────────────────────────────────────┐
│              RABBITMQ CLUSTER DEPLOYMENT                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                      VPC                                │   │
│   │  ┌─────────┐    ┌─────────┐    ┌─────────┐               │  │
│   │  │  AZ 1   │    │  AZ 2   │    │  AZ 3   │               │  │
│   │  │ ┌─────┐ │    │ ┌─────┐ │    │ ┌─────┐ │               │  │
│   │  │ │Node1│◄├────┼─┤Node2│◄├────┼─┤Node3│ │               │  │
│   │  │ └─────┘ │    │ └─────┘ │    │ └─────┘ │               │  │
│   │  └─────────┘    └─────────┘    └─────────┘               │  │
│   │                                                         │   │
│   │        Message replication across nodes                 │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   • 3 or 5 nodes across AZs                                     │
│   • Quorum queues for high availability                         │
│   • Automatic leader election                                   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

3. Deployment Modes

ModeEngineUse CaseHA
Single-InstanceActiveMQ, RabbitMQDev/Test
Active/StandbyActiveMQ onlyProduction HA
ClusterRabbitMQ onlyProduction HA

Network Accessibility

┌──────────────────────────────────────────────────────────────────┐
│              NETWORK ACCESS OPTIONS                              │
├──────────────────────────────────────────────────────────────────┤
│                                                                  │
│   PUBLIC ACCESS:                                                 │
│   ┌─────────────────────────────────────────────────────────┐    │
│   │  Internet ──→ Internet Gateway ──→ Amazon MQ            │    │
│   │  • Accessible from anywhere                             │    │
│   │  • ⚠️ Security risk (use strong auth)                   │    │
│   └─────────────────────────────────────────────────────────┘    │
│                                                                  │
│   PRIVATE ACCESS (Recommended):                                  │
│   ┌─────────────────────────────────────────────────────────┐    │
│   │  VPC only ──→ Amazon MQ (private endpoints)             │    │
│   │  • Not accessible from internet                         │    │
│   │  • Access via VPN, Direct Connect, or VPC peering       │    │
│   └─────────────────────────────────────────────────────────┘    │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

4. Protocols & Features

4.1 Supported Protocols

ProtocolDescriptionPort
OpenWireNative ActiveMQ protocol61617
AMQP 1.0Advanced Message Queuing Protocol5671
STOMPSimple Text Oriented Messaging61614
MQTTIoT messaging protocol8883
WebSocketBrowser-based clients61619

4.2 Message Patterns

┌──────────────────────────────────────────────────────────────────┐
│                  MESSAGE PATTERNS                                │
├──────────────────────────────────────────────────────────────────┤
│                                                                  │
│   QUEUE (Point-to-Point):                                        │
│   ┌─────────────────────────────────────────────────────────┐    │
│   │  Producer ──→ Queue ──→ Consumer (1 message = 1 consumer)│   │
│   │                                                         │    │
│   │  Similar to SQS                                         │    │
│   └─────────────────────────────────────────────────────────┘    │
│                                                                  │
│   TOPIC (Pub/Sub):                                               │
│   ┌─────────────────────────────────────────────────────────┐    │
│   │  Publisher ──→ Topic ──┬──→ Subscriber 1                │    │
│   │                        ├──→ Subscriber 2                │    │
│   │                        └──→ Subscriber 3                  │  │
│   │                                                         │    │
│   │  Similar to SNS                                         │    │
│   └─────────────────────────────────────────────────────────┘    │
│                                                                  │
│   Virtual Topics (ActiveMQ):                                     │
│   ┌─────────────────────────────────────────────────────────┐    │
│   │  Combine Topic semantics with Queue guarantees          │    │
│   │  Publisher ──→ Virtual Topic ──→ Consumer Queue 1       │    │
│   │                               ──→ Consumer Queue 2      │    │
│   │                                                         │    │
│   │  Similar to SNS + SQS Fan-out                           │    │
│   └─────────────────────────────────────────────────────────┘    │
│                                                                  │
└──────────────────────────────────────────────────────────────────┘

5. Security

5.1 Authentication & Authorization

┌─────────────────────────────────────────────────────────────────┐
│                  SECURITY LAYERS                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   AUTHENTICATION:                                               │
│   • Username/Password (Simple Authentication)                   │
│   • LDAP integration (ActiveMQ)                                 │
│                                                                 │
│   AUTHORIZATION:                                                │
│   • Broker-level permissions                                    │
│   • Queue/Topic-level access control                            │
│                                                                 │
│   ENCRYPTION:                                                   │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │  In-transit: TLS/SSL (required for public brokers)      │   │
│   │  At-rest: SSE with KMS                                  │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                 │
│   NETWORK:                                                      │
│   • Security Groups                                             │
│   • VPC endpoints                                               │
│   • Private deployment                                          │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

6. So sánh SQS/SNS vs Amazon MQ

6.1 Bảng so sánh

FeatureSQS/SNSAmazon MQ
TypeCloud-nativeManaged broker
ProtocolAWS APIsAMQP, MQTT, STOMP, OpenWire
ScalingUnlimited, autoLimited by instance
ManagementServerlessManage instances
MigrationNew appsLift-and-shift
CostPay per messagePay per instance hour
FeaturesBasicRich (routing, transactions)
HABuilt-inConfigure Active/Standby

6.2 Decision Tree

┌─────────────────────────────────────────────────────────────────┐
│                    DECISION TREE                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   Building new cloud-native application?                        │
│        │                                                        │
│   ┌────┴────┐                                                   │
│   ↓         ↓                                                   │
│  YES       NO                                                   │
│   │         │                                                   │
│   ↓         ↓                                                   │
│  SQS/     Migrating existing app?                               │
│  SNS           │                                                │
│           ┌────┴────┐                                           │
│           ↓         ↓                                           │
│          YES       NO                                           │
│           │         │                                           │
│           ↓         ↓                                           │
│       Amazon MQ   Need AMQP/MQTT/JMS?                           │
│                        │                                        │
│                   ┌────┴────┐                                   │
│                   ↓         ↓                                   │
│                  YES       NO                                   │
│                   │         │                                   │
│                   ↓         ↓                                   │
│               Amazon MQ   SQS/SNS                               │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

7. Best Practices

7.1 When to use Amazon MQ

Use CaseRecommendation
Migrate from on-prem ActiveMQ/RabbitMQ✅ Amazon MQ
Need JMS compatibility✅ Amazon MQ (ActiveMQ)
Need AMQP/MQTT protocols✅ Amazon MQ
New serverless application❌ Use SQS/SNS
Need unlimited scale❌ Use SQS/SNS

7.2 Production Recommendations

PracticeRecommendation
DeploymentActive/Standby hoặc Cluster
NetworkPrivate access (VPC only)
Instance sizeStart with m5.large, scale up
MonitoringCloudWatch metrics + Broker logs
BackupAutomatic + manual snapshots

7.3 High Availability

┌─────────────────────────────────────────────────────────────────┐
│                HA RECOMMENDATIONS                               │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│   ActiveMQ:                                                     │
│   • Use Active/Standby with EFS                                 │
│   • Enable automatic failover                                   │
│   • Configure client reconnection                               │
│                                                                 │
│   RabbitMQ:                                                     │
│   • Use 3-node cluster across AZs                               │
│   • Use Quorum Queues (not Classic Mirrored)                    │
│   • Configure publisher confirms                                │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

8. Common Exam Questions

Q1: When to use Amazon MQ over SQS/SNS?

A: Migrate existing apps using JMS, AMQP, MQTT, STOMP. No code changes needed.

Q2: Amazon MQ HA modes?

A: Single-instance (no HA), Active/Standby (ActiveMQ), Cluster (RabbitMQ)

Q3: Storage for ActiveMQ HA?

A: Amazon EFS (shared storage between Active/Standby)

Q4: Protocols supported?

A: OpenWire, AMQP, STOMP, MQTT, WebSocket

Q5: Can Amazon MQ scale automatically like SQS?

A: No, limited by broker instance size. SQS has unlimited scale.


Tài liệu tham khảo