Java Azure Function在本地不执行

huangapple 未分类评论54阅读模式
英文:

Java Azure Function Not Executing Locally

问题

你好,我正在使用Azure函数工作,我对此还不太了解,我已经使用以下原型创建了一个本地Java Azure函数项目:

mvn archetype:generate -DgroupId=com.mynew.serverlesstest -DartifactId=serverlessexample -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DinteractiveMode=false

这个模板有一个简单的Java函数。

执行mvn clean package命令后,会在函数的目标文件夹中生成function.json文件,下面是我的function.json内容:

{
  "scriptFile": "..\\serverlessexample-1.0-SNAPSHOT.jar",
  "entryPoint": "com.mynew.serverlesstest.Function.hello",
  "bindings": [
    {
      "type": "httpTrigger",
      "name": "req",
      "direction": "in",
      "authLevel": "anonymous",
      "methods": ["get", "post"]
    },
    {
      "type": "http",
      "name": "$return",
      "direction": "out"
    }
  ],
  "disabled": false
}

执行mvn azure-functions:run后,应用程序成功启动,并且在命令提示符中看到以下内容:

[06-04-2020 07:26:55] 初始化函数HTTP路由
[06-04-2020 07:26:55] 映射函数路由 'api/hello' [get,post] 到 'hello'
[06-04-2020 07:26:55] 映射函数路由 'api/HttpTrigger-Java' [get,post] 到 'HttpTrigger-Java'
[06-04-2020 07:26:55]
[06-04-2020 07:26:55] 主机已初始化 (424ms)
[06-04-2020 07:26:55] 主机已启动 (433ms)
[06-04-2020 07:26:55] 作业主机已启动

HTTP函数:

  hello: [GET,POST] 托管环境: 生产
  http://localhost:7071/api/hello
  内容根路径: C:\Users\ramaswamys\Development\azure-serverless\serverlessexample\target\azure-functions\serverlessexample-20200403205054646
  正在监听: http://0.0.0.0:7071
  应用程序已启动。按Ctrl+C关闭。
  
  HttpTrigger-Java: [GET,POST] http://localhost:7071/api/HttpTrigger-Java

  [06-04-2020 07:27:00] 主机锁定租约由实例ID '000000000000000000000000852CF5C4' 获得。

但是,当我尝试从Postman中访问API(http://localhost:7071/api/hello)时,我没有收到任何响应,在命令提示符中看到以下内容:

[06-04-2020 07:29:04] 执行HTTP请求: {
[06-04-2020 07:29:04]   "requestId": "af46115f-7a12-49a9-87e0-7fb073a66450",
[06-04-2020 07:29:04]   "method": "GET",
[06-04-2020 07:29:04]   "uri": "/api/hello"
[06-04-2020 07:29:04] }
[06-04-2020 07:29:05] 执行 'Functions.hello' (原因='此函数通过主机API以编程方式调用。', Id=7c712cdf-332f-413f-bda2-138f9b89025b)

之后什么都没有发生,30分钟后在命令提示符中会出现超时异常,如下所示:

Microsoft.Azure.WebJobs.Host: 函数 'Functions.hello' 超过了00:30:00的超时值。

有人能建议可能是什么原因,为什么Postman中看不到响应,我是否在做错什么?是否漏掉了任何配置?及时的帮助将不胜感激。

英文:

Hi all, I'm working on Azure functions, I'm new to this, I have created a local java Azure function project using the below archetype:

*mvn archetype:generate -DgroupId=com.mynew.serverlesstest -DartifactId=serverlessexample - 
DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype - 
DinteractiveMode=false*

*The template has a simple java function.

Upon executing a "mvn clean package" command, function.json gets generated in the target folder for the function, below is my function.json*

{
  "scriptFile" : "..\\serverlessexample-1.0-SNAPSHOT.jar",
  "entryPoint" : "com.mynew.serverlesstest.Function.hello",
  "bindings" : [ {
    "type" : "httpTrigger",
    "name" : "req",
    "direction" : "in",
    "authLevel" : "anonymous",
    "methods" : [ "get", "post" ]
  }, {
    "type" : "http",
    "name" : "$return",
    "direction" : "out"
  } ],
  "disabled" : false
}

on doing a mvn azure-functions:run, the application starts successfully , and I get below in the command prompt:

[06-04-2020 07:26:55] Initializing function HTTP routes
[06-04-2020 07:26:55] Mapped function route 'api/hello' [get,post] to 'hello'
[06-04-2020 07:26:55] Mapped function route 'api/HttpTrigger-Java' [get,post] to 'HttpTrigger-Java'
[06-04-2020 07:26:55]
[06-04-2020 07:26:55] Host initialized (424ms)
[06-04-2020 07:26:55] Host started (433ms)
[06-04-2020 07:26:55] Job host started

Http Functions:

      hello: [GET,POST] Hosting environment: Production
      http://localhost:7071/api/hello
      Content root path: C:\Users\ramaswamys\Development\azure- 
      serverless\serverlessexample\target\azure-functions\serverlessexample-20200403205054646
      Now listening on: http://0.0.0.0:7071
      Application started. Press Ctrl+C to shut down.   

      HttpTrigger-Java: [GET,POST] http://localhost:7071/api/HttpTrigger-Java

      [06-04-2020 07:27:00] Host lock lease acquired by instance ID 
      '000000000000000000000000852CF5C4'. 

But when I try hitting the api(http://localhost:7071/api/hello) from postman, I dont get any response, I see the below in the command prompt:

[06-04-2020 07:29:04] Executing HTTP request: {
[06-04-2020 07:29:04]   "requestId": "af46115f-7a12-49a9-87e0-7fb073a66450",
[06-04-2020 07:29:04]   "method": "GET",
[06-04-2020 07:29:04]   "uri": "/api/hello"
[06-04-2020 07:29:04] }
[06-04-2020 07:29:05] Executing 'Functions.hello' (Reason='This function was programmatically called 
via the host APIs.', Id=7c712cdf-332f-413f-bda2-138f9b89025b)

After this nothing happens:
after 30 min I get a timeout exception like below in the command prompt:

Microsoft.Azure.WebJobs.Host: Timeout value of 00:30:00 was exceeded by function: Functions.hello.

Can someone suggest what might be causing this, why no response is seen in the postman, Am I doing
any thing wrong here ? Am I missing any configuration stuff ? Timely help would be appreciated

答案1

得分: 0

请检查您的函数代码。

根据您提供的信息,触发器已经被触发。这意味着您触发器内部的代码逻辑尚未完成。换句话说,您成功触发了触发器,但您卡在触发器的内部逻辑中。请检查您的代码。

Java Azure Function在本地不执行

英文:

Please have a check of your function code.

From the info you offer, the trigger has already be triggered. So that means the code logic inside your trigger is not completed. In other words, you successfully triggered the trigger, but you are stuck in the internal logic of the trigger. Please check your code.

Java Azure Function在本地不执行

huangapple
  • 本文由 发表于 2020年4月6日 16:31:49
  • 转载请务必保留本文链接:https://java.coder-hub.com/61055793.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定