Tüm Ürünler
Search
Belge Merkezi

Function Compute:Asynchronous invocation

Son Güncelleme:Oct 08, 2026

Uzun süre çalışan, kaynak yoğun veya hata eğilimli mantığa sahip işlevler için, uygulama yanıt verebilirliğini artırmak ve trafik dalgalanmalarını güvenilir şekilde yönetmek amacıyla asenkron çağrıyı kullanın. Bir işlevi asenkron olarak çağırdığınızda, bir yanıt beklemeniz gerekmez. Function Compute isteği güvenilir işlem için dahili bir kuyrukta kalıcı hale getirir. Bu konu, asenkron çağrının kullanım durumlarını ve yaygın özelliklerini açıklar.

Kullanım durumları

Asenkron çağrı için örnek kullanım durumları şunlardır:

  • Ses ve video işleme

    Ses ve video iş yükleri için Function Compute kullanırken kodlama, kod çözme ve dönüştürme gibi zaman alan görevleri sıkça çalıştırırsınız. Bu görevleri asenkron olarak çağırarak ön yüzü engellemeden arka planda çalışmasını sağlayabilir ve kullanıcı deneyimini iyileştirebilirsiniz. Proje büyükse paralel işlem için birden fazla göreve bölebilir veya birden çok işlevi asenkron olarak çağırarak videoyu farklı formatlara dönüştürebilirsiniz. Bu yaklaşım toplam işlem süresini kısaltır.

  • Veri ETL işleme

    Bir veri çıkarma, dönüştürme ve yükleme (ETL) işlem hattında verileri bir kaynaktan çıkarma, dönüştürme ve hedef sisteme yükleme süreci; veritabanı sorguları, dosya G/Ç veya veri temizleme gibi birden çok bağımsız işlem içerebilir. Asenkron çağrı bu işlemlerin paralel çalışmasına olanak tanır, bu da işlem süresini azaltır ve sistem performansını artırır. Büyük veri kümelerini işlemek veya karmaşık veri dönüşümleri yapmak gibi uzun süre çalışan görevlerde asenkron çağrı, görevlerin arka planda yürütülmesini sağlar ve ön yüzü engellemeyerek kullanıcı deneyimini iyileştirir.

  • Web uygulamaları geliştirme

    Web uygulamalarını hızlıca oluşturmak için Function Compute'u diğer cloud hizmetleriyle birlikte kullanabilirsiniz. Kullanıcılar formları gönderdiğinde, arama sorgularını çalıştırdığında veya içerik açısından yoğun sayfaları yüklediğinde asenkron çağrı, arka uç yanıtlarının uzun süre beklenmesinden kaynaklanan sayfa donmalarını önleyebilir. Kullanıcılar fark edilir bir gecikme yaşamadan sayfanın diğer bölümleriyle etkileşime devam edebilir. Çok sayıda kullanıcının aynı anda uygulamaya eriştiği yüksek eşzamanlılık senaryolarında asenkron çağrı, istek yükünü dağıtarak hizmetin aşırı yüklenmesini engeller.

Ertelenmiş çağrı

Belirtilen bir gecikmeden sonra asenkron bir çağrıyı tetiklemek üzere Function Compute yapılandırabilirsiniz.

Kodunuza HTTP istek üstbilgisi x-fc-async-delay ekleyin. Değer saniye cinsinden olmalı ve (0, 3600) aralığında bulunmalıdır. Function Compute çalıştırma tetiklendiğinde bir zamanlayıcı başlatır ve x-fc-async-delay ile belirtilen gecikme süresinin ardından işlevi çağırır.

Yeniden deneme ilkesi

Asenkron çağrı mekanizması yerleşik hata işleme ve yeniden deneme özellikleri sunar. Bir adım başarısız olursa sistem genel iş akışını etkilemeden görevi yeniden planlayabilir. Asenkron bir işlev çağrısı başarısız olduğunda Function Compute çağrıyı otomatik olarak yeniden dener.

Yeniden deneme mekanizması

Aşağıdaki tabloda yaygın hatalar için varsayılan yeniden deneme ilkesi açıklanmaktadır.

Hata türü Yeniden deneme davranışı Faturalandırılır mı? Çözüm
HandledInvocationError ve UnhandledInvocationError Varsayılan olarak en fazla 3 kez yeniden denenir. İş gereksinimlerinize uygun olacak şekilde yeniden deneme sayısını ayarlayın. Evet — çağrı başına faturalandırılır. Ayrıntılar için bkz. Faturalandırmaya genel bakış. İşlev kodunuzdaki hatayı düzeltin.
Eşzamanlılık sınırı aşıldı Üstel geri çekilme kullanarak en fazla 5 saat boyunca yeniden dener. İlk yeniden deneme başarısızlıktan 0,5 saniye sonra başlar; sonraki aralıklar iki katına çıkar (1 sn, 2 sn, 4 sn, 8 sn, …). Hayır Kota Merkezi üzerinden eşzamanlılık kotanızı artırın. Varsayılan olarak her Alibaba Cloud hesabı bölge başına en fazla 100 örnek çalıştırabilir.
Dahili hata Yeniden deneme yok Hayır DingTalk üzerinden teknik destek ile iletişime geçin (grup kimliği: 64970014484).
Function Compute kaynakları yetersiz Yeniden deneme yok Hayır —

Yeniden deneme ilkesini yapılandırın

Function Compute maksimum yeniden deneme sayısını ve maksimum mesaj ömrünü özelleştirmenize olanak tanır.

  1. Log on to the Function Compute console. In the left-side navigation pane, 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, click the Tasks tab, and then click Task Mode to the right of Modify. In the Task Mode panel, set the following parameters. After you complete the configuration, click Deploy.


    Parameter


    Description


    Task Mode


    Specifies whether to enable Task Mode for an asynchronous task. For more information, see Asynchronous tasks.


    Maximum Retries

    The maximum number of retries for an asynchronous invocation. The value must be an integer from 0 to 8.

    By default, Function Compute retries a failed asynchronous invocation 3 times. You can adjust the number of retries based on your business requirements.


    Maximum Message Lifetime

    The maximum lifetime of a message in an asynchronous invocation queue. The value must be an integer from 1 to 604.800. The default value is 86.400. Unit: seconds.

    This duration is calculated from the time the asynchronous invocation is triggered. If the message lifetime exceeds the configured value, the message is discarded. Discarded messages are recorded by the Asynchronous Invocation Events monitoring metric in CloudMonitor. For more information about metrics, see Monitoring metrics.

Sonuç geri araması

When Function Compute receives an asynchronous invocation request, it persists the request and immediately returns a response without waiting for the request to execute. To retain requests that are discarded after all retries fail, or to notify a downstream service of the asynchronous invocation result, configure the result callback feature. After you configure a destination service, Function Compute automatically calls back the corresponding service based on the execution result when the asynchronous invocation is complete.

Nasıl çalışır?

The following figure shows the result callback workflow.

image

Kullanım durumları

  • Save discarded events for subsequent processing

    When an asynchronous request fails and fails all retries based on the configured policy, Function Compute discards the request. If you have configured a failure destination, Function Compute automatically pushes the context information of the failed request to a messaging service such as ApsaraMQ for RocketMQ for subsequent processing. You can also set another function as the destination service. In this case, Function Compute automatically pushes the context information of the failed request to that function to execute your custom error-handling logic.

  • Automatically notify downstream services of execution results

    After a successful execution, if a success destination is configured, the Function Compute system automatically pushes the request's context to the downstream destination service. For example, if you configure Function Compute to automatically decompress a ZIP file uploaded to OSS and want to receive a message notification upon completion, you can configure a result callback destination service for the target function.

Desteklenen hedef hizmetler

If an asynchronous invocation's result meets the configured conditions, Function Compute pushes the request context and data to the specified destination service. You can configure different destination services for different functions, aliases, and versions. The following destination services are supported for asynchronous invocation:

  • Simple Message Queue (formerly MNS)

  • Function Compute

  • EventBridge

  • ApsaraMQ for RocketMQ

Not
  • You can configure only 4,0 series instances of ApsaraMQ for RocketMQ as a destination service. 5,0 series instances are not supported.

  • For information about the payload limits for destination services, see Function runtime resource limits.

The configuration for asynchronous invocation destinations includes the following:

  • Event content for asynchronous invocation destinations

    When Simple Message Queue (formerly MNS), Function Compute, or ApsaraMQ for RocketMQ is the destination for an asynchronous function invocation, the event content has the following format.

    {
      "timestamp": 1660120276975,
      "requestContext": {
        "requestId": "xxx",
        "functionArn": "acs:fc:{regionid}:{accountid}:functions/xxxx",
           "condition": "FunctionResourceExhausted", 
            "approximateInvokeCount": 3
      },
      "requestPayload": "",
      "responseContext": {
        "statusCode": 200,
        "functionError": ""
      },
      "responsePayload": ""
    }

    Table 1. Parameter descriptions


    Parameter


    Description


    timestamp


    The timestamp of the invocation.


    requestContext


    The request context.


    requestContext.requestId


    The request ID of the asynchronous invocation.


    requestContext.functionArn


    The Alibaba Cloud Resource Name (ARN) of the asynchronously invoked function.


    requestContext.condition


    The error code of the invocation.


    requestContext.approximateInvokeCount


    The number of times the asynchronous invocation was executed. A value greater than 1 indicates that Function Compute has retried the invocation.


    requestPayload


    The original payload of the function request.


    responseContext


    The response context.


    responseContext.statusCode


    The system status code returned by the function invocation. If the status code is not 200, a system error occurred.


    responseContext.functionError


    The error message from the invocation.


    responsePayload


    The original payload returned by the function execution.

    When EventBridge is used as the destination for an asynchronous function invocation, the event is in the following format. For more information, see Event Overview.

    {
        "datacontenttype": "application/json",
        "aliyunaccountid": "143xxxx",
        "data": {
            "requestContext": {
                "condition": "",
                "approximateInvokeCount": 1,
                "requestId": "0fcb7f0c-xxxx",
                "functionArn": "acs:fc:{regionid}:{accountid}:functions/xxxx"
            },
            "requestPayload": "",
            "responsePayload": "",
            "responseContext": {
                "functionError": "",
                "statusCode": 200
            },
            "timestamp": 1660120276975
        },
        "subject": "acs:fc:{regionid}:{accountid}:functions/xxxx",
        "source": "acs:fc",
        "type": "fc:AsyncInvoke:succeeded",
        "aliyunpublishtime": "2021-01-03T09:44:31.233Asia/Shanghai",
        "specversion": "1.0",
        "aliyuneventbusname": "xxxxxxx",
        "id": "ecc4865xxxxxx",
        "time": "2021-01-03T01:44:31Z",
        "aliyunregionid": "cn-shanghai-vpc",
        "aliyunpublishaddr": "199.99.xxx.xxx"
    }
  • Payload limits

    The maximum payload limits for supported destination services are as follows:

    • Simple Message Queue (formerly MNS): 64 KB

    • Function Compute: subject to the limits described in Function runtime resource limits.

    • EventBridge: 64 KB

    • ApsaraMQ for RocketMQ: 4 MB

  • Avoid invocation loops

    When configuring a destination for an asynchronous execution, avoid creating an invocation loop. For example, you configure Function B as the destination for successful invocations of Function A, and Function A as the destination for successful invocations of Function B. In this case, if you asynchronously trigger Function A and it executes successfully, an invocation loop from A to B and then back to A may occur.

Hedef hizmeti yapılandırın

  1. Log on to the Function Compute console. In the left-side navigation pane, 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, click the Tasks tab, and then click Edit to the right of Modify. In the Task destination panel, set the following parameters. After you complete the configuration, click Deploy.

    • Configure a success destination

      Set Invoke Other Services upon Success to Enable, and then configure the destination service for successful executions. The parameters are described as follows:

      Parameter

      Description

      Destination Service

      Function Compute. When you select Function Compute as the destination service, you must configure the following parameters:

      • Function name: Specify the name of the destination function.

      • Version or alias: Specify the alias or version of the function.

      Simple Message Queue (formerly MNS). When you select Simple Message Queue (formerly MNS) as the destination service, you must configure the following parameters:

      • Destination type: Select a destination type. Valid values:

        • Queue:

          In the queue model, producers send messages to a queue and consumers pull messages from it. Each message can be consumed by only one consumer, making this model well suited for task distribution and workload processing.

        • Topic:

          In the topic model, a publisher sends a message to a topic, and SMQ pushes the message to all active subscriptions. Each subscription routes messages to a specified endpoint, such as a queue. This one-to-many model is well suited for event broadcasting and fan-out patterns.

      • Queue: Select the name of the Simple Message Queue (formerly MNS) queue. This parameter is required if you set Queue to Queue.

      • Topic: Select the name of the Simple Message Queue (formerly MNS) topic. This parameter is required if you set Topic to Topic.

      ApsaraMQ for RocketMQ. If you select ApsaraMQ for RocketMQ as the destination service, you must configure the following parameters:

      • Instance: Select the destination instance.

      • Topic: Select the destination topic.

      EventBridge. If you select EventBridge as the destination service, you must specify a Custom event bus.

    • Configure a failure destination

      Set Invoke Other Services upon Failure to Enable, and then configure the destination service for failed executions. The parameters are the same as those for a success destination.

Geri arama hataları

Callbacks to a destination service can fail due to insufficient permissions or service unavailability. Function Compute provides relevant metrics and logs that you can use for troubleshooting. The following table describes common errors and the corresponding system behaviors.


Error code


Cause


System behavior


5xx


Throttling or content errors.


The Function Compute system automatically retries with exponential backoff. The initial retry interval is 500 ms, and the maximum retry duration is 30 minutes.


4xx


Missing permissions, invalid request parameters (for example, the destination resource is deleted), or the request body exceeds the destination service limit.


Returns an error and records the error information.

Result callback metrics

If a callback to the destination service fails, Function Compute records the corresponding metrics in the console. You can log on to the Function Compute console. In the left-side navigation pane, choose . Then, in the Function Name list, click the name of the target function to view its metrics.


Metric name


Description


Destination Invocation Errors (FunctionDestinationErrors)


The number of failed attempts to invoke the destination for an asynchronous function invocation. The metric is aggregated by sum per minute or per hour.


Destination Invocation Successes (FunctionDestinationSucceed)


The number of successful attempts to invoke the destination for an asynchronous function invocation. The metric is aggregated by sum per minute or per hour.

For more information about monitoring metrics, see Monitoring Metrics.

SSS

Asenkron çağrı nasıl tetiklenir?

You can use one of the following methods to asynchronously invoke a function in Function Compute:

  • Log on to the Function Compute console, find the target function, go to the Test tab, select I want to make the call asynchronously., and then click Test Function.

  • Call the InvokeFunction API and set the x-fc-invocation-type parameter to Async.

  • Use Serverless Devs to configure an asynchronous invocation. Set the invocation-type parameter to Async. For more information, see Invoke a function.

  • Create a trigger that supports asynchronous invocation to asynchronously trigger the function. For more information, see Event-driven invocations.

  • When you use an HTTP trigger or a custom domain for an invocation, set the X-Fc-Invocation-Type request header to Async, as shown in the following example.

    curl -v -H "X-Fc-Invocation-Type: Async" https://example.cn-shenzhen.fcapp.run/$path
    Not
    • Call a Web Function: For example, if you use Flask and want to test a Python function with a route defined as @app.route('/test'), replace $path with test. When you test a Python function with a route defined as @app.route('/'), call the public endpoint of the HTTP trigger directly.

    • Invoke an Event Function: Directly call the public endpoint of the HTTP trigger.

Sonraki adımlar

To track the status of an asynchronous request at each stage, enable Task Mode. For more information, see Asynchronous tasks.