Amazon MQ

Learn via video courses
Topics Covered

Overview

Amazon MQ is a managed message broker service that makes it simple to move to a cloud-based message broker. A message broker enables software programs and components to interact with one another through the use of multiple programming languages, operating systems, and formal messaging protocols.

Amazon MQ now supports the Apache ActiveMQ and RabbitMQ engine types. Amazon MQ integrates with your existing applications and services, eliminating the need for you to manage, run, or maintain your messaging system.

What is a Message Broker?

Message Brokers allow distinct software systems to communicate and share information using different programming languages and platforms. We may develop a message Broker based on our needs. A broker can be either a single-instance or an active/standby broker.

A single Broker instance is contained in a single availability. It interacts with the application and the AWS storage location. It is employed in the creation and testing of software. Active/Standby Broker has two brokers in two separate availability zones for high availability. It will interact with the application as well as the shared storage location. It is suitable for automated failover. Amazon MQ supports data replication across AZs for both modes.

Message brokers enable software systems to communicate and share information, even when they utilize different programming languages on different platforms.

What is Amazon MQ, and How Does It Work?

With Amazon MQ, your application may leverage industry-standard messaging APIs and protocols such as Java Message Service (JMS), .NET Message Service (NMS), Advanced Message Queuing Protocol (AMQP), Simple (or Streaming) Text Oriented Message Protocol (STOMP), MQTT (MQ Telemetry Transport), and WebSocket. Because you don't have to rewrite any messaging code in your applications, you can quickly migrate your programs from any message broker that implements these standards to Amazon MQ.

what-is-amazon-mq

This is especially useful for organizations transitioning to the cloud since you can use Amazon MQ to bridge your local data center and the cloud, allowing hybrid architectures. Amazon MQ provides all the necessary capabilities to move from your old message broker to a managed service.

Some of the features are:

  • Queues and topics (with ordering)
  • Transient and persistent messaging
  • Local and distributed transactions
  • Composite and virtual destinations
  • Message filtering
  • Request/Reply
  • Scheduled Messages
  • Large Replies
  • Integration with AWS IAM that provides the ability to control the actions.
  • AWS KMS to create and manage keys for at-rest data encryption in MQ.
  • Stores messages redundantly across various Availability Zones.

Features of Amazon MQ

  • Service Management:
    With Amazon MQ, you can deploy a production-ready message broker in minutes using the AWS Management Console, AWS CloudFormation, the Command Line Interface (CLI), or simple API calls. Administrative responsibilities like configuring, broker configuration, software updates, and failure identification and restoration are handled by Amazon MQ. Amazon MQ is a fully managed messages broker service for Apache ActiveMQ and RabbitMQ that simplifies the setup, migration, and operation of message brokers on the AWS Cloud.

  • Security:
    Amazon MQ encrypts your communications both at rest and in transit. It's simple to guarantee that your messages are encrypted and securely preserved. SSL is used for broker connections, and access may be limited to a private endpoint inside your VPC, allowing you to isolate your broker within your virtualized environment. Amazon MQ is integrated with AWS Identity and Access Management (IAM) and provides you the ability to control the actions that your IAM users and groups can take on specific Amazon MQ brokers. Authentication from applications to the broker itself is provided using username and password-based authentication, and optionally using LDAP (Lightweight Directory Access Protocol) for ActiveMQ brokers.

  • Monitoring:
    AWS CloudTrail and Amazon CloudWatch are both linked with Amazon MQ. You may use CloudWatch to monitor metrics on your brokers, queues, and topics. You may, for example, check the depths of your queues and raise warnings if messages aren't being delivered. You may use CloudTrail to track, continuously monitor, and save Amazon MQ API requests.

  • Broker Instance Varieties:
    Amazon MQ presently offers seven broker instance types with varied CPU, memory, and network performance. The mq.t3.micro instances are intended for initial product assessment, whereas the mq.m5.large instances are for standard production use. Amazon MQ also provides single-instance brokers for evaluation and testing and replicating high-availability deployment models for operation.

  • Pay-per-use Pricing:
    Amazon MQ offers cost-effective and flexible capacity with no minimum price. You pay monthly for the number of hours your broker instance operates and the storage you utilize. It is simple and affordable to construct new brokers to enhance capacity. See Amazon MQ Pricing for additional information.

  • High Message Accessibility, Throughput, and Durability:
    Amazon MQ is built on the same extremely dependable infrastructure as the rest of Amazon Web Services. Amazon MQ for RabbitMQ clusters, which Amazon EBS supports, employs multi-AZ replication for highly available and messaging durability. Data transport for replicating is included at no extra charge. Clusters are formed behind a single endpoint to ensure high availability, ease of maintenance, and quick access from your application.

  • Broad Client Language Support:
    Develop using your favorite programming languages, including: Python, .NET, PHP, Python, JavaScript, Ruby, Java, and Go.

  • Message Routing:
    Before arriving in queues, messages in RabbitMQ brokers are routed through exchanges. RabbitMQ includes multiple exchange types for the common routing logic.

  • Durability:
    Amazon MQ for ActiveMQ provides durability-optimized brokers supported by Amazon Elastic File System (Amazon EFS) to provide high availability and message durability.  Connecting brokers to a network ensure active availability with near-instfailoverover. Amazon MQ also facilitates the creation of throughput-optimized message brokers supported by Amazon Elastic Block Store (EBS), which is ideal for high-throughput use cases such as high-volume order processing, stock trading, and text processing.

  • JMS Messaging Features:
    ActiveMQ provides all the standard JMS features including point-to-point (message queues), publish-subscribe (topics), request/reply, persistent and non-persistent modes, JMS transactions, and distributed (XA) transactions. In addition to basic queues and topics, ActiveMQ also supports more complex patterns such as composite destinations (producers can send the same message to multiple destinations, useful for real-time analytics) and virtual destinations (publishers broadcast messages via a topic to a pool of receivers subscribing through queues).

  • APIs and protocols that are industry-standard:
    ActiveMQ supports various clients, including Java Message Service (JMS) 1.1,.NET Message Service (NMS), and Node.js, Go, Python, Ruby, and C++. AMQP, STOMP, OpenWire, WebSocket, and MQTT are the wire-level protocols supported by ActiveMQ. This conformance to industry standards promotes the transition from old message brokers, allows veninteroperabilitylity, and aids in avoiding vendor reliance.

Why ActiveMQ?

We may utilize the database to store and process messages. However, anytime two apps communicate after the message is received, it should be processed and erased, i.e., an insert and delete operation should be performed for each message entry. It will run nicely for a few messages without hurting database performance. If we try to manage hundreds of messages between these apps, database performance will suffer, and the application will fail.

Amazon MQ is a message broker for Apache ActiveMQ, which can handle this use case. It will execute ActiveMQ broker maintenance and optimizations to save overhead. It provides a means for pushing messages to consumers rather than having them poll for new messages. Messaging manages intercommunication between various components of distributed systems or applications, removing the need for the application's design to exchange messages. As a result, the delay associated with processing new communications is reduced.

Amazon MQ Use Cases

  • It includes a use case for leveraging industry-level APIs:
    Amazon MQ uses industry-standard APIs and protocols such as JMS, NMS, AMQP, MQTT, STOMP, OpenWire, and WebSocket for messaging.

  • It handles administrative duties:
    Amazon MQ handles administrative duties like configuring, broker configuration, software updates, and failure detection and recovery.

  • Messages are stored in several availability zones:
    To guarantee redundancy, Amazon MQ archives your message in various Availability Zones.

  • It supports a variety of brokers:
    Amazon MQ supports single-instance brokers for testing and evaluation and standby/active brokers for highly available operations. Amazon MQ immediately shifts to the backup broker in case of a broker breakdown or even a total AZ outage.

Amazon MQ Pricing

You just pay for what you use with Amazon MQ. There are no minimum costs or obligations required. You pay for the time your message broker instance operates, the amount of storage you utilize monthly, and regular data transmission costs.

  • Broker Discount:
    Hourly instance utilization Message broker use is charged hourly, with prices ranging based on the size of the message broker instance and whether you select a single-instance broker, a 3-node cluster, or perhaps an active/standby broker.

  • Storage Broker Pricing:
    Storage utilization per month For Amazon MQ for ActiveMQ, two types of broker storage are available: durability optimized (using AWS EFS) and throughput optimized (using AWS EBS). All RabbitMQ brokers use Amazon EBS. Amazon MQ charges you according to the mean space you use each month. This is determined by totaling the GB utilized each hour and dividing it by the number of hrs in the month, yielding a figure in "GB-Months".

  • AWS No-Cost Tier:
    Amount and time frame Amazon MQ is available for a free trial. The AWS Free Tier allows up to 750 hours per month of a single-instance mq.t2.micro or mq.t3.micro broker utilizing ActiveMQ or RabbitMQ. It also provides one year of durability-optimized Amazon EFS storage for ActiveMQ and 20GB of Amazon EBS storage for RabbitMQ. AWS Free Tier access is provided for 12 months to new AWS customers. For further information, see the AWS Free Tier.

  • Fees for data transfer:
    You will be charged $0.01/GB in each direction for traffic routed between brokers within availability zones within the same region. You will be invoiced for bandwidth out of each area on cross-region networks according to the EC2 pricing schedule. For example, from US-East (North Carolina) to US-West (Oregon), you'll pay $0.02/GB. AWS area bandwidth is not taxed. There are no additional costs for Amazon MQ for ActiveMQ Networks of Brokers. Each broker in the networks will be charged, as well as any data transfer costs for network traffic between AZs or regions. There are no additional costs for data transport fees inside the cluster for Amazon MQ for RabbitMQ clusters. You will be charged normal AWS data transfer fees for data transmitted into and out of Amazon MQ.

  • Pricing example:
    If you are operating an mq.m5.large active/standby ActiveMQ broker in the US East (N. Virginia) region with Amazon EFS storage type, and your broker uses 1GB of storage for 15 days in March, and 10GB of storage for the final 16 days in March, you would pay the following for the month:

Broker instance charge:

Instance usage (in hours) = 31 days x 24 hrs/day = 744 hours x $0.576 (price per hour for an mq.m5.large active/standby broker in the US East (N. Virginia) region) = $428.54

Storage charge:

Storage usage in GB-Hours = [1GB x 15 days x (24 hrs/day)] + [10GB x 16 days x (24 hrs/day)] = 4,200 GB-Hours

Convert GB-Hours to GB-Months to calculate the monthly charge:

4,200 GB-Hours / 24 hrs / 31 days = 5.64516 GB-Months - 5 GB-Months free = 0.64516 x $0.30 (the price per GB-Month in US East region) = $0.19

Total charge = $428.54 (broker instance charge) + $0.19 (storage charge) = $428.73*

Getting Started with Amazon MQ

  • Click on the "Get Started" button, as shown below, to go to the AWS MQ console page.

    getting-started-with-amazon-mq getting-started-with-amazon-mq-2

  • Select the engine type from available engines such as Apache ActiveMQ and RabbitMQ. We have selected ActiveMQ. getting-started-with-amazon-mq-3

  • Now select the deployment mode and storage types. Here we have selected Single instance broker and durability optimized(uses Amazon EFS), respectively.

    getting-started-with-amazon-mq-4

  • Now, in the configure settings, you have to provide the Broker name, Broker instance type, and ActiveMQ Access, under which you can select the simple authentication and authorization option and provide the username and password. Finally, click on the "Create Broker" button.

    getting-started-with-amazon-mq-5

  • Creating a broker will take almost 15 minutes, so you have to wait for the creation of the broker. After your broker enters the running state, you can copy the endpoints from the connection section, as shown below.

    getting-started-with-amazon-mq-6

  • Create a Java application named AmazonMQConnection. Create two classes that will act as two components in this application. One is the Producer class, and the other is the Consumer.

Producer Class:

Consumer Class:

  • Convert Java application into Maven project. Update the pom.xml file with the following code. This will allow the application to work with ActiveMQ.

  • Run the Producer class to send a message and Run the Consumer class to receive the message sent by the Producer. You can refer to the links given below:

Benefits of Amazon MQ

  • Delegate operational responsibilities:
    Amazon MQ manages message broker administration and maintenance, automatically provisioning infrastructure for high availability, broker setup, software updates, and failure detection and recovery.

  • Easy durable messaging:
    When you connect message brokers, Amazon MQ is automatically provided for high availability and message durability. Amazon MQ replicates messages across different Availability Zones (AZ) within an AWS region and will remain operational if a component or AZ fails.

  • Move quickly:
    Amazon MQ uses industry-standard APIs and protocols for communications. This allows you to transition from any message broker that supports these standards to Amazon MQ by modifying the endpoints of apps that connect to Amazon MQ.

  • Integration of Applications:
    It allows apps written in various languages and running on different operating systems to interact with one another.

  • Stability:
    There is no requirement for producers and consumers to be available simultaneously. Provides a queue for managing any number of requests at any time.

  • Asynchronous: means that instead of waiting for a response, one program can send a message and proceed with other tasks.

  • Disconnected:
    Because the queue is located between the application and communication is routed via it, the failure of one system does not affect other applications.

  • Cost Savings:
    You just need to pay for the storage and broker instances you utilize.

Amazon MQ vs Amazon SQS

Amazon MQAmazon SQS
1. Suitable for the existing applications which leverage open-source message brokers.1. Best suitable to build new cloud-based messaging applications.
2. There is no need for the availability of producers or consumers simultaneously. It provides a queue to manage any number of requests at any point in time.2. Amazon SQS relaxes some of the queueing system properties to achieve high redundancy and ensure no messages are lost, i.e., in some rare situations, messages may arrive out of order, and some messages can be repeated.
3. Pay only for storage and broker instances as you use, i.e., pay per hour and GB.3. Need to pay per request.
4. It is API compatible.4. Provide simple APIs.
5. Is feature rich.5. Provides unlimited throughput.

Conclusion

  • Amazon MQ minimizes operational duties by automating message broker deployment, setup, and maintenance for you.
  • Amazon MQ uses industry-standard APIs and protocols to connect to your existing applications, so you can quickly switch to AWS without changing code.
  • Amazon MQ manages ActiveMQ administration and maintenance as a managed service. Responsibilities include broker provision, patching, high-availability fault diagnosis and restoration, and message durability.
  • Amazon MQ provides users with direct access to the ActiveMQ console and industry-standard messaging APIs and protocols such as Java Message Service (JMS), .NET Message Service (NMS), Advanced Message Queuing Protocol (AMQP), Simple (or Streaming) Text Oriented Message Protocol (STOMP), MQTT (MQ Telemetry Transport), and WebSocket.
  • Users can establish a single-instance Amazon MQ broker or an active/standby pair that spans AZs with rapid, automated failover for development and testing.
  • They get data replication between AZs in any case, as well as a pay-as-you-go broker instance and message storage approach.