首页 > 解决方案 > 如何在 Java Azure 函数中使用事件中心触发器

问题描述

我正在尝试创建一个从 Azure 事件中心触发的 Java 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 中的错误弹出窗口: VSCode中的弹出错误

我一直在寻找数小时和一页又一页的谷歌搜索。我究竟做错了什么?

标签: javaazureazure-functionsazure-java-sdkjava-annotations

解决方案


请更换

@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString"), String message, final ExecutionContext context)

@EventHubTrigger(name = "msg", eventHubName = "mticallhub", connection = "EHubConnectionString") String message, final ExecutionContext context)

在此处输入图像描述


推荐阅读