Azure Java函数-502-错误的网关 [英] Azure Java function -502-Bad Gateway

查看:76
本文介绍了Azure Java函数-502-错误的网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了以下链接中给出的Java azure函数:

I have created Java azure function as given on following link:

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访问

Now when i try to access using curl

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

or postman 

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

然后出现以下错误,我想知道是否有人遇到相同的错误.

Then get following error , I am wonder if anyone getting same error.

502错误的网关

502-Bad Gateway

指定的CGI应用程序遇到错误,服务器终止了该过程.

The specified CGI application encountered an error and the server terminated the process.

日志:

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 *

Also tried to remove all and added CORS *

存储空间:

推荐答案

似乎您遇到了在门户网站上,功能运行库已更新为2.0.11857.0(检查功能"应用程序设置面板).虽然maven插件尚未更新以赶上.

On portal, function runtime has been updated to 2.0.11857.0(Check your Function app settings panel). While maven plugin has not been updated to catch up.

因此,旧的mvn插件构建的代码与最新的运行时不兼容.

So the code built by old mvn plugin is not compatible with latest runtime.

解决方法是将函数运行时固定到上一个.转到应用程序设置"面板,然后将FUNCTIONS_EXTENSION_VERSIONbeta更改为2.0.11776-alpha.

Workaround is to pin your function runtime to previous one. Go to Application settings panel and change FUNCTIONS_EXTENSION_VERSION from beta to 2.0.11776-alpha.

请参见此问题讨论更多详细信息,新插件即将推出.

See this issue discussion for more details, new plugin is coming soon.

更新6/15

新插件已发布.参见有关Jave语言工作者的通知.

  • 使用最新的Maven Azure Functions原型创建新项目

  • Create new project using latest Maven Azure Functions Archetype

mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype 

  • 更新现有项目以使用最新的Azure Function mvn插件

  • Update existing project to use latest Azure Function mvn plugin

    1. 功能代码(* .java)

    1. function code(*.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.*;
    

  • pom.xml

  • 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)再找到excludeArtifactIdsazure-functions-java-core,更改为azure-functions-java-library.

    2)Find one more azure-functions-java-core of excludeArtifactIds, change to azure-functions-java-library.

    3)查找azure-functions-maven-plugin,将版本更改为1.0.0-beta-2.请参见专家.

    3)Find azure-functions-maven-plugin,change version to 1.0.0-beta-2. See Latest version on maven.

  • 这篇关于Azure Java函数-502-错误的网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆