Tüm Ürünler
Search
Belge Merkezi

Function Compute:Message Queue for MNS konu tetikleyicileri

Son Güncelleme:Oct 08, 2026

Simple Message Queue (formerly MNS) konuları olay kaynağı olarak davranabilir ve EventBridge ile Function Compute arasında entegrasyon sağlayabilir. Simple Message Queue (formerly MNS) konu tetikleyicisi, Simple Message Queue (formerly MNS) konunuza yeni bir mesaj gönderildiğinde ilişkili işlevi otomatik olarak çalıştırır. Bu sayede gelen mesajlar için özel işleme mantığını kolayca uygulayabilirsiniz.

Arka plan bilgileri

Message Queue for MNS, verimli, güvenilir, güvenli, kullanımı kolay ve esnek şekilde ölçeklenebilen dağıtık bir mesajlaşma hizmetidir. Uygulama geliştiricilerin dağıtık bileşenler arasında veri ve bildirim aktarmasına ve gevşek bağlı sistemler oluşturmasına yardımcı olur. Message Queue for MNS içinde konu, mesajların yayımlandığı hedeftir. Bir yayıncı, PublishMessage API'sini çağırarak bir konuya mesaj yayınlayabilir ve konuya abone olanlar bu mesajı alır. API ayrıntıları için bkz. PublishMessage.

<!--@ph {"id":"e1fff8e0e8hg8","data-node":"4265519"}-->Simple Message Queue (formerly MNS)<!--/@ph--> konu tetikleyicisi yapılandırdığınızda, işleviniz ilgili Simple Message Queue (formerly MNS) konusuna abone olarak kaydedilir. Bir yayıncı Simple Message Queue (formerly MNS) konusuna mesaj gönderdiğinde, mesaj içeriği işleve iletilerek yürütme tetiklenir. Mesaj içeriği, işlev işleyicisine event parametresi olarak geçirilir. Daha fazla bilgi için bkz. Temel bilgiler.

The integration of Message Queue for MNS and Function Compute provides the following benefits:

  • Perform advanced processing on messages before you send them by email or SMS.

  • You do not need to host a service for an HTTP endpoint.

  • Implement rich custom processing, such as sending messages to Slack or persisting specific messages.

Önkoşullar

Kullanım notları

  • The topic in Message Queue for MNS and the function in Function Compute must be in the same region.

  • Avoid recursive invocations.

    When you write function code, make sure that the function does not contain the following logic: Topic A triggers Function B, and Function B publishes a new message to Topic A. This may cause infinite recursive invocations.

Adım 1: Message Queue for MNS konu tetikleyicisi oluşturma

  1. Log on to the Function Compute console. In the navigation pane on the left, choose Function Management > Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the target function.

  3. On the function details page, select the Trigger tab, and then click Create Trigger.

  4. In the Create Trigger panel, configure the parameters, and then click OK.

    Parametre

    Eylemler

    Örnek

    Trigger Type

    Message Queue for MNS Topic Trigger - Asynchronous Invocation seçeneğini belirleyin.

    Simple Message Queue (formerly MNS) konu tetikleyicisi

    Name

    Özel bir tetikleyici adı girin.

    trigger-mns

    Version or Alias

    Varsayılan değer LATEST şeklindedir. Başka bir sürüm veya takma ad için tetikleyici oluşturmak istiyorsanız önce işlev ayrıntıları sayfasının sağ üst köşesinde ilgili sürüme veya takma ada geçiş yapın. Sürümler ve takma adlar hakkında genel bilgi için bkz. Sürümleri yönetme ve Takma adları yönetme.

    LATEST

    MNS Bölgesi

    Konunun bulunduğu bölgeyi seçin. Simple Message Queue (formerly MNS) konusu ile Function Compute işlevi aynı bölgede olmalıdır.

    China (Chengdu)

    Topic

    Listeden konuyu seçin.

    Mytopic

    Filtre Etiketi

    Bir mesaj filtre etiketi girin.

    İşlev yalnızca belirtilen filtre etiketini içeren mesajları aldığında tetiklenir.

    tag

    Olay Biçimi

    Bir olay biçimi seçin. Geçerli değerler:

    • STREAM

    • JSON

    JSON

    Yeniden Deneme İlkesi

    Bir yeniden deneme ilkesi seçin. Geçerli değerler:

    • Backoff Retry

    • Üstel azalan yeniden deneme

    Yeniden deneme ilkesinin nasıl seçileceğine ilişkin rehberlik için bkz. NotifyStrategy.

    Geri Çekilerek Yeniden Dene

    Role Name

    AliyunMNSNotificationRole seçeneğini belirleyin.

    Not

    Bu türde bir tetikleyiciyi ilk kez oluşturuyorsanız OK düğmesine tıkladıktan sonra açılan iletişim kutusunda Autorize Now seçeneğini belirleyin.

    AliyunMNSNotificationRole

Adım 2: İşlev giriş parametrelerini yapılandırma

  1. On the OK tab of the function details page, click the image.png icon next to Code and select Test Function from the drop-down list.

  2. In the Configure Test Parameters panel, select Configure Test Parameters or Create New Test Event. Enter an event name and event content, and then click OK.

    Messages published to a Simple Message Queue (formerly MNS) topic are processed based on the notifyContentFormat. The processed message is the event parameter for the function handler. For more information, see NotifyContentFormat.

    • If you set Event Format to STREAM when you create the trigger:

      • If the message does not include message attributes (MessageAttributes), the event format is as follows.

        Not

        If the message does not include message attributes (MessageAttributes), the event content is the raw message body as a string.

        # Message body.
        'hello topic'
      • If the message includes message attributes (MessageAttributes), the event format is as follows.

        Not

        The event content includes key-value pairs related to MessageAttributes. For more information, see PublishMessage.

            {
                "body": "hello topic",
                "attrs": {
                    "Extend": "{\\"key\\":\\"value\\"}"
                }
            }                    
    • If you set Event Format to JSON when you create the trigger:

      • If the message does not include message attributes (MessageAttributes), the event format is as follows.

            {
                "TopicOwner": "118620210433****",
                "Message": "hello topic",
                "Subscriber": "118620210433****",
                "PublishTime": 1550216480040,
                "SubscriptionName": "test-fc-subscribe",
                "MessageMD5": "BA4BA9B48AC81F0F9C66F6C909C3****",
                "TopicName": "Mytopic",
                "MessageId": "2F5B3C082B923D4EAC694B76D928****"
            }        
                                    
      • If the message includes message attributes (MessageAttributes), the event format is as follows.

        Not

        The event content includes key-value pairs related to MessageAttributes. For more information, see PublishMessage.

            {
                "key": "value",
                "TopicOwner": "118620210433****",
                "Message": "hello topic",
                "Subscriber": "118620210433****",
                "PublishTime": 1550216302888,
                "SubscriptionName": "test-fc-subscribe",
                "MessageMD5": "BA4BA9B48AC81F0F9C66F6C909C3****",
                "TopicName": "Mytopic",
                "MessageId": "2F5B3C281B283D4EAC694B742528****"
            }
                                    

    The following table describes the fields in the event parameter.


    Parametre


    Tür


    Örnek


    Açıklama


    key


    Dize


    value


    Mesaj özniteliklerinden alınan anahtar-değer çiftleri.


    TopicOwner


    Dize


    118620210433****


    Konuya sahip olan hesabın kimliği.


    Message


    Dize


    hello topic


    Mesaj içeriği.


    Subscriber


    Dize


    118620210433****


    Kullanıcının hesap kimliği.


    PublishTime


    Tamsayı


    1550216302888


    Mesajın yayınlandığı zaman.


    SubscriptionName


    Dize


    test-fc-subscribe


    Abonelik adı.


    MessageMD5


    Dize


    BA4BA9B48AC81F0F9C66F6C909C3****


    Mesaj gövdesinin MD5 karma değeri.


    TopicName


    Dize


    Mytopic


    Konu adı.


    MessageId


    Dize


    2F5B3C281B283D4EAC694B742528****


    Mesaj kimliği.

Adım 3: İşlev kodunu yazma ve test etme

After you create a Simple Message Queue (formerly MNS) topic trigger, write and test your function code to verify that it works as expected.

  1. On the Modify Existing Test Event tab of the function details page, write code in the editor, and then click Code.

    This section uses Python code as an example. You can use the following sample code as a template for a Simple Message Queue (formerly MNS) topic trigger.

    import json
    import logging
    
    def handler(event, context):
      logger = logging.getLogger()
      logger.info("mns_topic trigger event = {}".format(event))
      # For example, record the event to Tablestore.
      return "OK"                     
  2. Click Deploy.

    After the execution is complete, you view the execution result above the Test Function tab.

Daha fazla bilgi

In addition to the Function Compute console, you can also configure triggers in the following ways:

To modify or delete a trigger, see Tetikleyicileri yönetme.