MNS topics can be used as event sources in EventBridge to connect to Function service. Functions are subscribers to topics. An MNS topic trigger is used to trigger a function to perform custom processing on messages that are published to an MNS topic.

Background information

MNS is a distributed messaging service that features scalability, high efficiency, reliability, security, and availability. MNS allows application developers to transfer data and notifications between the distributed components of an application and build a loosely coupled system. In MNS, a topic is the destination to which messages are published. A publisher can call the PublishMessage operation to publish a message to a topic, and a subscriber to the topic receives the message. For more information about the PublishMessage operation, see PublishMessage.

Configuring a trigger for an MNS topic is equivalent to registering a function as a subscriber to the MNS topic. When a publisher publishes a message to the MNS topic, the message is passed to the function and used as the event parameter of the function handler to trigger the function. For more information, see Input parameters of functions.

The integration of MNS and Function Compute has the following benefits:
  • Allows you to perform advanced processing on a message before you send the message in an email or a text message.
  • Allows you not to create services at HTTP endpoints.
  • Supports abundant custom processing. For example, you can send a message to Slack or persist a specified message.

Usage notes

  • We recommend that you deploy MNS topics and functions of Function service in the same region.

    An MNS topic trigger allows a function to subscribe to a topic that resides in a different region. However, network latency is increased when the function and topic reside in different regions, especially when one region is in the Chinese mainland and the other region is outside the Chinese mainland.

  • You must avoid recursive invocations.

    Avoid the following logic when you write code for a function: Topic A triggers Function B, and Function B publishes a new message to Topic A. This logic results in an infinite loop of function invocations.