如何在 Java Azure 函数中使用事件中心触发器
How to use an Event Hub Trigger in a Java Azure Function
我正在尝试创建一个 Java Azure Functions 来触发 Azure 事件中心。我正在关注这些代码片段:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=java#example
这是我的代码:
package com.function;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.function.annotation.*;
import java.util.Optional;
public class function {
@FunctionName("MTI")
public void EventHubProcess(
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString"), String message, final ExecutionContext context)
{
context.getLogger().info("Java HTTP trigger processed a request: " + message);
}
}
这是我在构建时遇到的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project func-MTI-test-zyg-001: Compilation failure
[ERROR] /C:/JavaStuff/FunctionApps/func-MTI-test-zyg-001/src/main/java/com/function/Function.java:[34,105] illegal start of type
这是 VSCode 中的错误弹出窗口:
我找了好几个小时,一页又一页地搜索 Google。我做错了什么?
请更改
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString"), String message, final ExecutionContext context)
至
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString") String message, final ExecutionContext context)
我正在尝试创建一个 Java Azure Functions 来触发 Azure 事件中心。我正在关注这些代码片段:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=java#example
这是我的代码:
package com.function;
import com.microsoft.azure.functions.*;
import com.microsoft.azure.function.annotation.*;
import java.util.Optional;
public class function {
@FunctionName("MTI")
public void EventHubProcess(
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString"), String message, final ExecutionContext context)
{
context.getLogger().info("Java HTTP trigger processed a request: " + message);
}
}
这是我在构建时遇到的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project func-MTI-test-zyg-001: Compilation failure
[ERROR] /C:/JavaStuff/FunctionApps/func-MTI-test-zyg-001/src/main/java/com/function/Function.java:[34,105] illegal start of type
这是 VSCode 中的错误弹出窗口:
我找了好几个小时,一页又一页地搜索 Google。我做错了什么?
请更改
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString"), String message, final ExecutionContext context)
至
@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString") String message, final ExecutionContext context)