All Products
Search
Document Center

:Overview

Last Updated:Dec 11, 2023

After you integrate a Message Service (MNS) topic with a function in Function Compute by using EventBridge, the function subscribes to the topic. A trigger is created for the MNS topic. The topic trigger can trigger the execution of the function, which then processes the messages published to the MNS topic.

Background

MNS is a distributed messaging service that features high scalability, efficiency, reliability, security, and convenience. MNS allows application developers to transfer data and notifications between the distributed components of an application and build a loosely coupled system. In MNS, messages are published to topics. 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, 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 Basic information.

The following benefits are delivered after MNS and Function Compute are integrated:

  • Allows you to perform advanced processing on a message before you send the message in an email or a text message.

  • Does not require you to create services at HTTP endpoints.

  • Supports abundant custom processing. For example, you can send a message to Slack or persist a specified message.

image

Usage notes

  • The MNS topic must reside in the same region as the function in Function Compute.

  • 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, which then triggers Function B again. This logic results in an infinite loop of function invocations.