Overview and What You Will Learn
Amazon MQ runs managed RabbitMQ and ActiveMQ brokers, and Amazon MSK runs managed Apache Kafka. Both exist for teams that already depend on an open messaging standard (AMQP, JMS, MQTT or the Kafka protocol) and do not want to rewrite their code for AWS-native services such as SQS, SNS or Kinesis.
By the end of this lab you will be able to:
- Decide when Amazon MQ is the right choice and when SQS and SNS are better
- Choose a high-availability layout for RabbitMQ and ActiveMQ brokers
- Choose between MSK Provisioned (Standard or Express brokers) and MSK Serverless
- Create an MSK Serverless cluster and a topic with IAM authentication
- Explain what MSK Connect and Amazon Managed Service for Apache Flink add
- Choose between MSK and Kinesis Data Streams, and avoid the Firehose-to-Flink mistake
Why This Matters in Production
Picture a bank whose transaction system was built over many years on ActiveMQ. Moving to SQS would mean rewriting every producer and consumer, which is slow and risky. Amazon MQ runs the same broker as a managed service, so the application connects with the same protocol and client libraries and only the endpoint changes. In the same way, a media analytics team with deep Kafka experience can move to MSK without learning a new streaming API. The skill is knowing when an open protocol is a real requirement and when an AWS-native service is simpler and cheaper.
Core Principles
Start from what the application already speaks, not from the service name. A legacy protocol points to Amazon MQ, the Kafka API points to MSK, and a new application with no protocol constraint is usually better off on SQS, SNS or Kinesis.
AMQP, JMS or MQTT?} B -->|Yes| C[Amazon MQ] B -->|No| D{Event streaming
and replay?} D -->|No| E[SQS and SNS] D -->|Yes| F{Kafka API or
Kafka ecosystem?} F -->|Yes| G[Amazon MSK] F -->|No| H[Kinesis Data Streams] classDef start fill:#475569,color:#FFFFFF classDef check fill:#F1F5F9,color:#1E293B classDef mq fill:#F97316,color:#FFFFFF classDef native fill:#10B981,color:#FFFFFF classDef kafka fill:#326CE5,color:#FFFFFF class A start class B,D,F check class C mq class E,H native class G kafka
The open protocols that Amazon MQ preserves are:
- AMQP, used by RabbitMQ and many enterprise systems
- JMS, the Java messaging API, and OpenWire, ActiveMQ's native protocol
- MQTT, common for IoT devices
- STOMP and WebSocket-based messaging
RememberUse Amazon MQ to migrate existing applications that depend on these protocols and cannot change their client code. For a new application built on AWS, SQS and SNS scale further, need no broker management and usually cost less.
Detailed Step-by-Step Practical Lab
How to Choose a High-Availability Layout for Amazon MQ
Amazon MQ offers a single-instance broker for development and a redundant layout for production, and the layout depends on the engine. Both engines store data redundantly, but only the redundant layouts survive the loss of an Availability Zone without downtime.
| RabbitMQ | ActiveMQ Classic | |
|---|---|---|
| Dev layout | Single-instance broker | Single-instance broker |
| Production layout | Cluster of three nodes in three AZs | Active/standby pair in two AZs |
| Replication | Quorum queues (or classic mirroring on 3.x) | Shared Amazon EFS storage |
| Client endpoint | One endpoint on a Network Load Balancer | Failover URL listing both brokers |
RabbitMQ cluster deployments are three broker nodes behind a Network Load Balancer, spread across three AZs and sharing users, queues and state. Clients connect to the load balancer endpoint, not to a chosen node. On RabbitMQ 3.x, Amazon MQ manages classic queue mirroring across all nodes. From RabbitMQ 3.13, quorum queues are available by setting the queue type to quorum, and on RabbitMQ 4 (4.2 at the time of writing) quorum queues are the default and mirroring of classic queues is deprecated. Prefer quorum queues for anything that must not lose messages.
ActiveMQ active/standby runs two brokers in two AZs. The active broker serves clients while the standby waits, and both use the same Amazon EFS file system (the durability-optimized storage type), so when the active broker fails the standby takes over with the messages already present. Amazon EBS storage lives in a single AZ and does not support active/standby, so use EFS for production. Clients should use the failover transport so they reconnect on their own:
failover:(ssl://b-1234abcd-1.mq.ap-south-1.amazonaws.com:61617,ssl://b-1234abcd-2.mq.ap-south-1.amazonaws.com:61617)Look up what your account and Region offer before you pick versions and instance types, and review the options without creating a broker:
aws mq describe-broker-engine-types --engine-type RABBITMQaws mq describe-broker-engine-types --engine-type ACTIVEMQaws mq describe-broker-instance-options --engine-type RABBITMQTipAlways create Amazon MQ brokers with private access inside a VPC, restrict the broker security group to your application subnets, and use TLS ports (
5671for AMQP over TLS,61617for OpenWire over TLS).
How to Choose Between MSK Provisioned and MSK Serverless
Amazon MSK runs Apache Kafka without you managing servers, patching or broker replacement, and you keep using the standard Kafka API and tools. It comes in two cluster types: Provisioned (where you choose a broker type) and Serverless (where you do not size anything).
| MSK Provisioned | MSK Serverless | |
|---|---|---|
| Capacity planning | You choose broker type, count and storage | None, scales automatically |
| Cost model | Per broker hour plus storage | Throughput-based pricing (check the current price list) |
| Configuration control | High on Standard brokers | Limited topic and cluster settings |
| Authentication | IAM, SASL/SCRAM, mTLS, plaintext (Standard) | IAM only |
| Best for | Steady, high-throughput, tunable workloads | Spiky or unknown traffic, new teams |
MSK Provisioned has two broker types. Standard brokers run on EC2 with EBS storage and give the most control, including tiered storage and storage throughput settings. Express brokers (generally available since November 2024) manage storage for you and AWS describes them as scaling faster and handling more throughput per broker. Express brokers need a recent Kafka version and cannot be switched to from an existing Standard cluster, so you create a new cluster and migrate with MSK Replicator. Check the current broker types and Region availability on the MSK documentation page before you decide, because both change often.
For a production Provisioned cluster, use three brokers in three AZs and set topics to replication factor 3 with min.insync.replicas=2. Producers should use acks=all, which means a write succeeds only after at least two replicas have it, so a single broker failure loses nothing.
kafka-topics.sh --bootstrap-server "$BOOTSTRAP" --command-config client.properties \ --create --topic payments.events \ --partitions 6 \ --replication-factor 3 \ --config min.insync.replicas=2MSK Serverless is not available in every Region, so confirm that your target Region (for example ap-south-1) supports it before you design around it.
How to Create an MSK Serverless Cluster and a Topic
MSK Serverless requires IAM access control and does not support Kafka ACLs. It manages replication for you, so you cannot set the replication factor, and you create topics with the Kafka command-line tools rather than the console.
export AWS_REGION=ap-south-1 aws kafka create-cluster-v2 \ --cluster-name devops-kafka-serverless \ --serverless 'VpcConfigs=[{SubnetIds=[subnet-0a1b2c3d4e5f60001,subnet-0a1b2c3d4e5f60002],SecurityGroupIds=[sg-0123456789abcdef0]}],ClientAuthentication={Sasl={Iam={Enabled=true}}}' CLUSTER_ARN=arn:aws:kafka:ap-south-1:123456789012:cluster/devops-kafka-serverless/11111111-2222-3333-4444-555555555555-s3 # Wait until the state is ACTIVE (this can take 10 to 15 minutes)aws kafka describe-cluster-v2 --cluster-arn "$CLUSTER_ARN" --query 'ClusterInfo.State' # IAM authentication uses port 9098BOOTSTRAP=$(aws kafka get-bootstrap-brokers --cluster-arn "$CLUSTER_ARN" \ --query BootstrapBrokerStringSaslIam --output text)echo "$BOOTSTRAP"Run the Kafka tools from an EC2 instance or container in the same VPC, with the aws-msk-iam-auth library on the Kafka classpath. The role needs kafka-cluster:Connect, kafka-cluster:CreateTopic, kafka-cluster:WriteData, kafka-cluster:ReadData and the related describe permissions on the cluster, topic and group resources.
# client.properties for IAM authenticationcat > client.properties << 'EOF'security.protocol=SASL_SSLsasl.mechanism=AWS_MSK_IAMsasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandlerEOF # Create a topic (replication is managed by MSK Serverless)kafka-topics.sh --bootstrap-server "$BOOTSTRAP" --command-config client.properties \ --create --topic devops-orders --partitions 3 # Produce, then consume from the beginningkafka-console-producer.sh --bootstrap-server "$BOOTSTRAP" \ --producer.config client.properties --topic devops-orders kafka-console-consumer.sh --bootstrap-server "$BOOTSTRAP" \ --consumer.config client.properties --topic devops-orders --from-beginningHow to Move Data with MSK Connect
Kafka Connect copies data between Kafka and other systems using ready-made connectors. MSK Connect runs the Connect workers for you, so you supply a connector plugin and configuration and AWS handles the workers, scaling and recovery.
- S3 sink connector: every message from an MSK topic is written to an S3 bucket, giving you an archive and a data lake feed without custom code
- Debezium source connector: changes in a database such as PostgreSQL stream into a Kafka topic as they happen (change data capture)
A connector needs a custom plugin (the connector JAR uploaded to S3), a worker configuration, a service execution role with access to the cluster and its target, and network access from the connector's subnets to the brokers. Start the connector from the console or aws kafkaconnect create-connector, and watch the connector's lag and error metrics in CloudWatch.
How to Process Streams in Real Time with Amazon Managed Service for Apache Flink
Amazon Managed Service for Apache Flink (formerly Kinesis Data Analytics) runs Apache Flink applications without you managing the cluster. Flink processes event streams continuously, so it suits work that must happen as data arrives rather than in batches.
Typical Flink jobs include:
- Enriching and transforming events in flight
- Aggregating over time windows, such as the sum of payments in the last five minutes
- Joining two streams, such as matching orders to payments
- Detecting event patterns, such as three failed logins followed by a large transfer
- Filtering and routing events to different destinations
It reads from sources such as Kinesis Data Streams and MSK, and writes to destinations such as MSK, Kinesis, S3 and Amazon Data Firehose. Flink takes automatic checkpoints for fault tolerance, so if the application restarts it resumes from the last checkpoint. A savepoint is a manual, consistent snapshot used for planned changes such as a version upgrade or a code change, and in the managed service these are exposed as application snapshots. By default the service takes a snapshot when you stop or update an application, but confirm the setting for your application before relying on it.
Common MistakeTrying to use Amazon Data Firehose as a Flink source. Firehose is a delivery service that loads data into a destination, and it is not a stream you can read from. If Flink must process the data first, put it in Kinesis Data Streams or MSK, process it with Flink, and send the result to Firehose for delivery to S3 or Redshift.
The common production pattern is: applications write events to MSK topics, Managed Flink reads them and enriches or aggregates in real time, and the output goes back to MSK or on to S3.
How to Choose Between MSK and Kinesis Data Streams
Both services stream and retain events in order, so the decision is about protocol, ecosystem and how much control you want. Choose MSK when you need the Kafka API or ecosystem, and choose Kinesis Data Streams when you are building AWS-native and want the simplest option.
| Amazon MSK | Kinesis Data Streams | |
|---|---|---|
| API | Apache Kafka (open standard) | AWS proprietary |
| Portability | Runs on any cloud or on premises | AWS only |
| Ecosystem | Kafka Connect, Debezium, Kafka Streams | AWS integrations such as Lambda and Firehose |
| Retention | Configurable, with tiered storage for long retention | 24 hours by default, up to 365 days |
| Ordering | Per partition | Per shard |
| Scaling unit | Partition and broker | Shard, or on-demand capacity |
| Operations | More settings to tune | Simpler |
Choose MSK when:
- The team already knows Kafka and uses Kafka tools or client libraries
- You need Kafka Connect connectors, compacted topics or exactly-once semantics
- Portability matters, because the application might run on another cloud
Choose Kinesis Data Streams when:
- The team is new to streaming and wants the least to operate
- The design is AWS-only and leans on Lambda, Firehose or other Kinesis services
How to Monitor Brokers and Clean Up the Lab
Watch the signals that show a broker or consumer in trouble before users do.
| Service | What to watch | Why |
|---|---|---|
| MSK | Consumer lag per group and topic | Consumers falling behind producers |
| MSK | Under-replicated partitions, disk used | Broker or storage problems |
| Amazon MQ | Queue depth and consumer count | Backlog or missing consumers |
| Amazon MQ | Broker CPU, memory and storage | An undersized broker |
Clean up the lab to stop charges:
aws kafka delete-cluster --cluster-arn "$CLUSTER_ARN"Production Best Practices & Common Pitfalls
- Pick the simplest service that meets the protocol requirement. New applications rarely need Amazon MQ.
- Use redundant layouts in production. RabbitMQ clusters and ActiveMQ active/standby with EFS survive an AZ failure, single-instance brokers do not.
- Prefer RabbitMQ quorum queues for durability on new queues.
- Configure Kafka for durability. Replication factor 3,
min.insync.replicas=2andacks=all. - Keep clusters private. Use VPC access, security groups and IAM or mTLS authentication, and never expose brokers publicly.
- Monitor consumer lag. It is the earliest warning that a pipeline is falling behind.
- Keep Flink fed from streams. Read from Kinesis Data Streams or MSK, and use Firehose only as a sink.
| Mistake | Problem | Fix |
|---|---|---|
| Amazon MQ for a new app | More operations and cost than SQS and SNS | Use SQS and SNS unless you need an open protocol |
| ActiveMQ on EBS for HA | EBS does not support active/standby | Use EFS durability-optimized storage |
| Replication factor 1 topics | Data loss when a broker fails | Replication factor 3 with min.insync.replicas=2 |
| Firehose as a Flink source | Firehose cannot be read from | Use Kinesis Data Streams or MSK as the source |
| Setting replication on MSK Serverless | Not configurable | Let MSK manage it |
| Assuming Serverless exists in your Region | Cluster creation fails | Check Region support first |
Quick Reference & Troubleshooting Commands
| Task | Command |
|---|---|
| List MQ engine versions | aws mq describe-broker-engine-types --engine-type RABBITMQ |
| List MQ instance options | aws mq describe-broker-instance-options --engine-type ACTIVEMQ |
| Describe a broker | aws mq describe-broker --broker-id ID |
| Create MSK Serverless | aws kafka create-cluster-v2 --serverless ... |
| Get IAM bootstrap servers | aws kafka get-bootstrap-brokers --cluster-arn ARN |
| Create a topic | kafka-topics.sh --bootstrap-server BS --command-config client.properties --create --topic NAME |
| Check consumer lag | kafka-consumer-groups.sh --bootstrap-server BS --command-config client.properties --describe --group GROUP |
| Delete an MSK cluster | aws kafka delete-cluster --cluster-arn ARN |
| Symptom | First check | What to look for |
|---|---|---|
| Client cannot connect to MSK | Security group and port | Port 9098 open from the client for IAM |
| Authentication failed on MSK | IAM role and client properties | kafka-cluster:Connect allowed, IAM library on the classpath |
| Consumers falling behind | Consumer group lag | Too few consumers or partitions, slow processing |
| ActiveMQ clients stay down after failover | Connection URL | Failover transport lists both broker endpoints |
| Flink job reads nothing | Source configuration | Source is a stream (Kinesis or MSK), not Firehose |