Alibaba Cloud Message Service (MNS) is an efficient, reliable, secure, easy-to-use, and scalable distributed messaging service. MNS allows developers to transmit data and notifications on the distributed components of an application and build a loosely coupled system.

MNS can be used to push various types of messages.

MNS provides the following types of services:

  • Queue-based MNS services
  • Topic-based MNS services

Differences between these two types of services:

  • MNS queues are used to send messages from one sender client to another receiver client.
  • MNS topics are used to send messages from one publisher client to multiple subscriber clients. MNS topics support multiple message pushing methods.

Overview of queue-based MNS services

MNS queues provide one-to-one message consumption services. Queue-based MNS services feature high reliability and concurrency. Each message in a queue can be consumed only by one client.

An MNS queue can be compared to a sushi restaurant. Multiple sushi chefs make exquisite sushi (messages) and put them on a rotating conveyor. Then, customers take the pieces they ordered from the conveyor.

Benefits of queue-based MNS services

  • Supports various parameters

    You can customize the parameters of a queue to meet various business needs. In addition to standard queues, you can also specify the message delay period or priority for a queue.

  • Supports a large number of concurrent requests

    MNS queues support concurrent requests from multiple producer and consumer clients. After a message is consumed from a queue, the message cannot be consumed again within a specified period. You can determine the limit of concurrent requests based on business needs.

  • Guarantees message delivery

    MNS ensures that a message in a queue can be consumed at least once during the message validity period. MNS is integrated into the Alibaba Cloud account system in which resources are isolated between users. This ensures that only authorized entities can retrieve your messages in MNS queues.

  • Supports distributed transactions

    MNS queues provide an efficient solution to process distributed transactional messages.

  • Supports the log management feature

    You can view the lifecycle of each message, which involves message sending, receiving, and deletion. Log management allows you to troubleshoot issues with ease.

    For more information, see Log management.

  • Supports CloudMonitor

    You can view queue information in the CloudMonitor console and customize alarm rules to provide reminder notifications when any business exception occurs.

    For more information, see CloudMonitor.

Topic-based MNS services

MNS topics are used to send messages from one publisher client to multiple subscriber clients. MNS topics support multiple message pushing methods.

A topic can be compared to a newspaper subscription service. When a new issue of the newspaper is released, customers (including partners of the post office) can use one of the following methods to retrieve the newspaper:

  • Ask a post office courier to deliver the newspaper to a specific address such as your house.
  • Post office couriers deliver the newspaper to a newsstand where it can be collected by the client.
  • Ask the post office to send the electronic version of the newspaper to a specified email address.
  • Ask the post office to send SMS messages that include the newspaper content to your mobile phone.
  • Ask the post office to use the WebSocket API to push the electronic version of the newspaper to multiple clients.
  • Ask the news agency to use Alibaba Cloud Mobile Push to push the electronic version of the newspaper to a mobile application.

The following figure shows the procedure.

  • A topic has multiple subscriptions that are specified with different endpoints, including HTTP endpoints, queues, and email addresses.
  • After being published to the topic, a message is pushed to the endpoints that are specified in subscriptions.
  • You can specify a tag for a subscription to filter messages. If you do not specify a tag for a subscription, messages are pushed to the specified endpoint no matter whether you specify message tags. If you specify a tag for a subscription, messages can be pushed to the specified endpoint only when you specify the same tag for messages.

Benefits of topic-based MNS services

  • Supports notification messages

    The MNS server automatically pushes messages to specified callback URLs to prevent unnecessary request polling and resource consumption of clients. You can take advantage of resources for handling businesses. Additionally, you can avoid dependence on other message service clients and prevent the system instability that is caused by excessive code introduction.

    For more information, see HttpEndpoint, Sign requests that are sent to endpoints, Manage topics, and On-premises debug tool of HTTP endpoints.

    If you do not want to provide callback URLs due to network security or other reasons, you can push messages to MNS queues and retrieve messages from the queues. You can use queues to consume messages in topics.

    For more information, see Push messages to queues and Send messages from one producer client to multiple consumer clients without exposing the endpoints of consumer clients.

  • Supports broadcast messages
    • A message that is published to a topic can be pushed to multiple subscriber clients based on specified message pushing methods and endpoints. You can use multiple channels to receive the message at the same time.
    • Once published, the message is automatically pushed to multiple endpoints. This ensures the atomicity of message pushing.
  • Supports using tags to filter messages

    In addition to broadcast messages, MNS supports using tags to filter messages. By specifying a tag for a subscription, you only receive messages with the same tag from the topic. If you specify a tag for a subscription and specify a tag for a message when calling the PublishMessage operation, MNS pushes the message to the specified endpoint that is specified only when the tags are the same.

    For more information, see Topic management.

  • Supports multiple endpoints

    MNS supports multiple endpoints, including:

  • Guarantees message delivery

    During the message validity period, messages that are published to a topic will be automatically pushed to subscriber clients based on specified retry policies and content formats. Retry policies include:

    • BACKOFF_RETRY

      Specifies three retry attempts. The interval between retries is a random value between 10 and 20 seconds.

    • EXPONENTIAL_DECAY_RETRY

      Specifies 176 retry attempts that are executed within one day. The interval between retries increases exponentially to a maximum of 512 seconds. The specific intervals between retries are as follows: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512... 512 (The number 512 appears for 167 times).

    Message content formats include:

    • XML. The request body contains the message content and the parameters of messages.
    • JSON. The request body contains the message content and the parameters of messages.
    • SIMPLIFIED (Text format). The request body only contains the message content.

    For more information, see NotifyStrategy and NotifyContentFormat.

  • Supports the log management feature

    Log entries are generated when a message is published to a topic and pushed to endpoints. The information about pushing retries and whether the message is successfully pushed to endpoints are recorded in log entries. You can use log entries to retrieve the lifecycle of the message. Log management allows you to troubleshoot issues with ease.

    For more information, see Log management.

  • Supports CloudMonitor

    You can monitor the message pushing status in the CloudMonitor console and customize alarm rules to provide reminder notifications when a large amount of messages fail to be pushed.

    For more information, see CloudMonitor.