Amazon MQ

Amazon MQ is a managed message broker service that makes it easy to migrate to a message broker in the cloud. A message broker allows software applications and components to communicate using various programming languages, operating systems, and formal messaging protocols.

Currently, Amazon MQ supports Apache ActiveMQ and RabbitMQ engine types. Creating and connecting to a broker instance is slightly different for each broker engine. Choose one of the engine types that you want to use for detailed information on creating and connecting to a broker. 

Creating & connecting to an ActiveMQ :

Below steps to be followed for connecting:

Step 1: Create an ActiveMQ broker:

The first and most common Amazon MQ task is creating a broker. The following example shows how you can use the AWS Management Console to create a basic broker.

Amazon MQ
  1. Sign in to the Amazon MQ console.
  2. On the select broker engine page, choose Apache ActiveMQ.
  3. On the select deployment and storage page, in the Deployment mode and storage type section, do the following:
    -> Choose the Deployment mode (for example, Active/standby broker)
    -> Choose the Storage type (for example, EBS).
    -> Choose Next.
  4. On the Configure settings page, in the Details section, do the following:
    -> Enter the Broker name.
    -> Choose the Broker instance type (for example, mq.m5.large).
  5. In the ActiveMQ Web Console access section, provide a Username and Password. The following restrictions apply to broker usernames and passwords:
    -> Your username can contain only alphanumeric characters, dashes, periods, underscores, and tildas (- . _ ~).
    -> Your password must be at least 12 characters long, contain at least 4 unique characters and must not contain commas, colons, or equal signs (,:=).
  6. Choose Deploy.
    While Amazon MQ creates your broker, it displays the Creation in progress status. Creating the broker takes about 15 minutes. When your broker is created successfully, Amazon MQ displays the Running status.
  7. Choose MyBroker. On the MyBroker page, in the Connect section, note your broker’s ActiveMQ web console URL, for example:
    “https://b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9-1.mq.us-east-2.amazonaws.com:8162”
    Also, note your broker’s wire-level protocol Endpoints. like:
    “amqps://b-c8349341-ec91-4a78-ad9c-a57f23f235bb.mq.us-west-2.amazonaws.com”

Step 2: Connect a Java application to your broker

After you create an Amazon MQ ActiveMQ broker, you can connect your application to it. The following examples show how you can use the Java Message Service (JMS) to create a connection to the broker, create a queue, and send a message.

There are some prerequisites for further details check this link. Below are some :

Enable VPC attributes

To ensure that your broker is accessible within your VPC, you must enable the enableDnsHostnames and enableDnsSupport VPC attributes. For more information, see DNS Support in your VPC in the Amazon VPC User Guide.

Enable inbound connections

  1. Sign in to the Amazon MQ console.
  2. From the broker list, choose the name of your broker (for example, MyBroker).
  3. On the MyBroker page, in the Connections section, note the addresses and ports of the broker’s web console URL and wire-level protocols.
  4. In the Details section, under Security and network, choose the name of your security group or  .The Security Groups page of the EC2 Dashboard is displayed.
  5. From the security group list, choose your security group.
  6. At the bottom of the page, choose Inbound, and then choose Edit.
  7. In the Edit inbound rules dialog box, add a rule for every URL or endpoint that you want to be publicly accessible (the following example shows how to do this for a broker web console).
    1. Choose Add Rule.
    2. For Type, select Custom TCP.
    3. For Port Range, type the web console port (8162).
    4. For Source, leave Custom selected and then type the IP address of the system that you want to be able to access the web console (for example, 192.0.2.1).
    5. Choose Save.Your broker can now accept inbound connections.

Add Java dependencies

Add the activemq-client.jar and activemq-pool.jar packages to your Java class path. For more information about activemq-client.jar, see Initial Configuration in the Apache ActiveMQ documentation.

Step 3: (Optional) Connect to an AWS Lambda function:

AWS Lambda can connect to and consume messages from your Amazon MQ broker. When you connect a broker to Lambda, you create an event source mapping that reads messages from a queue and invokes the function synchronously. The event source mapping you create reads messages from your broker in batches and converts them into a Lambda payload in the form of a JSON object.

Creating and connecting to a RabbitMQ broker

Step 1: Create a RabbitMQ broker

The first and most common Amazon MQ task is creating a broker. The following example shows how you can use the AWS Management Console to create a basic broker.

  1. Sign in to the Amazon MQ console.
  2. On the Select broker engine page, choose RabbitMQ, and then choose Next.
  3. On the Select deployment mode page, choose the Deployment mode, for example, Cluster deployment, and then choose Next.
  4. On the Configure settings page, in the Details section, the following:
    -> Enter the Broker name.
    -> Choose the Broker instance type (for example, mq.m5.large).
  5. On the Configure settings page, in the RabbitMQ access section, provide a Username and Password. The following restrictions apply to broker usernames and passwords:
    -> Your username can contain only alphanumeric characters, dashes, periods, and underscores (- . _). This value must not contain any tilde (~) characters. Amazon MQ prohibits using guest as a username.
    -> Your password must be at least 12 characters long, contain at least 4 unique characters and must not contain commas, colons, or equal signs (,:=).
  6. Choose Next.
  7. On the Review and create page, you can review your selections and edit them as needed.
  8. Choose Create broker.
    While Amazon MQ creates your broker, it displays the Creation in progress status.Creating the broker takes about 15 minutes.When your broker is created successfully, Amazon MQ displays the Running status.
  9. Choose MyBroker. On the MyBroker page, in the Connect section, note your broker’s ActiveMQ web console URL, for example:
    “https://b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9-1.mq.us-east-2.amazonaws.com”
    Also, note your broker’s wire-level protocol Endpoints. like:
    “amqps://b-c8349341-ec91-4a78-ad9c-a57f23f235bb.mq.us-west-2.amazonaws.com”

Step 2: Connect a JVM-based application to your broker

After you create a RabbitMQ broker, you can connect your application to it.  You can connect to RabbitMQ brokers using supported RabbitMQ client libraries for a variety of languages. For more information about supported RabbitMQ client libraries, see RabbitMQ client libraries and developer tools.

Step 3: (Optional) connect to an AWS Lambda function

AWS Lambda can connect to and consume messages from your Amazon MQ broker. When you connect a broker to Lambda, you create an event source mapping that reads messages from a queue and invokes the function synchronously. The event source mapping you create reads messages from your broker in batches and converts them into a Lambda payload in the form of a JSON object.

——– “If you don’t use an Amazon MQ broker (and don’t foresee using it in the near future), it is a best practice to delete it from Amazon MQ to reduce your AWS costs.” ———-

Benefits of using Amazon MQ:

  • Amazon MQ is suitable for enterprise IT pros, developers, and architects who are managing a message broker themselves–whether on-premises or in the cloud–and want to move to a fully managed cloud service without rewriting the messaging code in their applications.
  • Amazon MQ manages the work involved in setting up a message broker, from provisioning the infrastructure capacity you request–including broker instances and storage–to installing the broker software. Once your broker is up and running, Amazon manages ongoing software upgrades, security updates, and fault detection and recovery.
  • Amazon MQ makes it easy to create a message broker with the computing and storage resources that fit your needs. You can create, manage, and delete brokers using the AWS Management Console, Amazon MQ REST API, or the AWS Command Line Interface.
  • Amazon MQ stores messages redundantly across multiple Availability Zones (AZs) for message durability. With active/standby brokers, Amazon MQ automatically fails over to a standby instance in the event of a failure so you can continue sending and receiving messages.
  • Amazon MQ works with your existing applications and services without the need to manage, operate, or maintain your own messaging system.
  • Connecting your current applications to Amazon MQ is easy because it uses industry-standard APIs and protocols for messaging, including JMS, NMS, AMQP, STOMP, MQTT, and WebSocket.

Difference bw Amazon MQ & Azure Service Bus

Developers describe Amazon MQ as “Managed Message Broker Service for ActiveMQ“. Amazon MQ is a managed message broker service for Apache ActiveMQ that makes it easy to set up and operate message brokers in the cloud. On the other hand, Azure Service Bus is detailed as “*Reliable cloud messaging as a service (MaaS) *”. It is a cloud messaging system for connecting apps and devices across public and private clouds. You can depend on it when you need highly-reliable cloud messaging service between applications and services, even when one or more is offline.

Alternatives to Amazon MQ and Azure Service Bus

1. Amazon SQS

Transmit any volume of data, at any level of throughput, without losing messages or requiring other services to be always available. With SQS, you can offload the administrative burden of operating and scaling a highly available messaging cluster, while paying a low price for only what you use.

2. RabbitMQ

RabbitMQ gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.

3. IBM MQ

It is a messaging middleware that simplifies and accelerates the integration of diverse applications and business data across multiple platforms. It offers proven, enterprise-grade messaging capabilities that skillfully and safely move information.

4. ActiveMQ

Apache ActiveMQ is fast, supports many Cross Language Clients and Protocols, comes with easy to use Enterprise Integration Patterns and many advanced features while fully supporting JMS 1.1 and J2EE 1.4. Apache ActiveMQ is released under the Apache 2.0 License.

5. Kafka

Kafka is a distributed, partitioned, replicated commit log service. It provides the functionality of a messaging system, but with a unique design.

References :