代码之家  ›  专栏  ›  技术社区  ›  Rhett Prestwich

如何在JavaAzure函数中使用事件中心触发器

  •  0
  • Rhett Prestwich  · 技术社区  · 4 年前

    我正在尝试创建一个JavaAzure函数,该函数从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中的错误弹出窗口: popup error in VSCode

    我已经找了好几个小时了,一页又一页的谷歌搜索结果累坏了。我做错什么了?

    1 回复  |  直到 4 年前
        1
  •  2
  •   Frank Gong    4 年前

    请换衣服

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

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

    enter image description here