簡體   English   中英

Azure Java功能-502-Bad Gateway

[英]Azure Java function -502-Bad Gateway

我已經創建了Java azure函數,如下面的鏈接所示:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven

Java類:

package com.khan;

import java.util.*;
import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;

/**
 * Azure Functions with HTTP Trigger.
 */
public class Function {
    /**
     * This function listens at endpoint "/api/hello". Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP Body" {your host}/api/hello
     * 2. curl {your host}/api/hello?name=HTTP%20Query
     */
    @FunctionName("hello")
    public HttpResponseMessage<String> hello(
            @HttpTrigger(name = "req", methods = {"get", "post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

        context.getLogger().info("Java HTTP trigger processed a request.");

        // Parse query parameter
        String query = request.getQueryParameters().get("name");
        String name = request.getBody().orElse(query);

        if (name == null) {
            return request.createResponse(400, "Please pass a name on the query string or in the request body");
        } else {
            return request.createResponse(200, "Hello, " + name);
        }

    }
}

功能已成功創建和部署

在此輸入圖像描述

現在當我嘗試使用curl訪問時

curl -w '\n' https://sundaydemo-20180526141357482.azurewebsites.net -d AzureFunctions

or postman 

https://sundaydemo-20180526141357482.azurewebsites.net/api/hello

然后得到以下錯誤,我很想知道是否有人得到同樣的錯誤。

502錯誤的網關

指定的CGI應用程序遇到錯誤,服務器終止了該進程。

日志:

2018-05-31T02:02:50  Welcome, you are now connected to log-streaming service.
2018-05-31T02:03:50  No new trace in the past 1 min(s).
2018-05-31T02:04:50  No new trace in the past 2 min(s).
2018-05-31T02:05:50  No new trace in the past 3 min(s).
2018-05-31T02:06:50  No new trace in the past 4 min(s).
2018-05-31T02:07:50  No new trace in the past 5 min(s).
2018-05-31T02:08:50  No new trace in the past 6 min(s).
2018-05-31T02:09:17.161 [Information] Executing 'Functions.hello' (Reason='This function was programmatically called via the host APIs.', Id=b43d17c9-35c0-4c84-ab7e-26a8ec721fe9)
2018-05-31T02:10:50  No new trace in the past 1 min(s).
2018-05-31T02:11:50  No new trace in the past 2 min(s).
2018-05-31T02:12:50  No new trace in the past 3 min(s).
2018-05-31T02:13:50  No new trace in the past 4 min(s).
2018-05-31T02:14:17.183 [Error] Timeout value of 00:05:00 exceeded by function 'Functions.hello' (Id: 'b43d17c9-35c0-4c84-ab7e-26a8ec721fe9'). Initiating cancellation.
2018-05-31T02:14:17.451 [Error] Microsoft.Azure.WebJobs.Host: Timeout value of 00:05:00 was exceeded by function: Functions.hello.
2018-05-31T02:14:17.572 [Error] Executed 'Functions.hello' (Failed, Id=b43d17c9-35c0-4c84-ab7e-26a8ec721fe9)
2018-05-31T02:15:50  No new trace in the past 1 min(s).
2018-05-31T02:16:50  No new trace in the past 2 min(s).
2018-05-31T02:17:50  No new trace in the past 3 min(s).
2018-05-31T02:18:50  No new trace in the past 4 min(s).

在此輸入圖像描述

在此輸入圖像描述

在此輸入圖像描述

在此輸入圖像描述

還試圖刪除所有並添加CORS *

在此輸入圖像描述

儲存:

在此輸入圖像描述

在此輸入圖像描述

您似乎遇到了Function Runtime 2.0 Preview Breaking Change

在門戶網站上,函數運行時已更新為2.0.11857.0 (檢查“功能”應用程序設置面板)。 雖然maven插件尚未更新以趕上。

因此,舊的mvn插件構建的代碼與最新的運行時不兼容。

解決方法是將函數運行時固定到上一個。 轉到“應用程序設置”面板,將FUNCTIONS_EXTENSION_VERSIONbeta更改為2.0.11776-alpha

有關更多詳細信息,請參閱此問題討論 ,新插件即將推出。

更新十五分之六

新插件已經發布。 請參閱jave語言工作者的通知

  • 使用最新的Maven Azure Functions Archetype創建新項目

     mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype 
  • 更新現有項目以使用最新的Azure Function mvn插件

    1. 功能代碼(* .java)

      之前

       import com.microsoft.azure.serverless.functions.annotation.*; import com.microsoft.azure.serverless.functions.*; 

      之后(刪除無服務器)

       import com.microsoft.azure.functions.annotation.*; import com.microsoft.azure.functions.*; 
    2. 的pom.xml

      1)前

       <dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-functions-java-core</artifactId> <version>1.0.0-beta-2/3</version> </dependency> 

       <dependency> <groupId>com.microsoft.azure.functions</groupId> <artifactId>azure-functions-java-library</artifactId> <version>1.0.0-beta-4</version> </dependency> 

      2) excludeArtifactIds一個azure-functions-java-core excludeArtifactIds azure-functions-java-coreexcludeArtifactIds ,改成azure-functions-java-library

      3)找到azure-functions-maven-plugin ,將版本更改為1.0.0-beta-2 查看maven的最新版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM