Azure / azure-functions-java-library

Contains annotations for writing Azure Functions in Java
MIT License
43 stars 43 forks source link

Add definition for "warmup" trigger #108

Closed jeffhollan closed 2 years ago

jeffhollan commented 4 years ago

There's a new trigger for Azure Functions that allows your app to "warmup" before routing traffic during scale operations. Because in Java apps function.json metadata is generated during mvn package we need to add an annotation for @WarmupTrigger

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-warmup?tabs=java

/ cc @kulkarnisonia16 @alexkarcher-msft @amamounelsayed

shayannyc25 commented 4 years ago

hi any update on this? i am trying to create a java azure function like: @FunctionName("Warmup") public void warmUpFunction(ExecutionContext context){ try{ connection = DriverManager.getConnection(connectionUrl); context.getLogger().info("EventHubTriggerJavaToSQLDB.WarmUp function executed.");

    }catch (SQLException e) {
        context.getLogger().info("Exception while getting="+e.toString());
        e.printStackTrace();
    }  
}

and getting error on start up: The 'Warmup' function is in error: At least one binding must be declared

vlkuznet commented 3 years ago

I can't comment to the issue status, but wanted to share the following workaround.

After building, manually add a bindings element to the function.json file for your warmup triggered function: { "bindings": [ { "type": "warmupTrigger", "direction": "in", "name": "warmupContext" } ] ... Reference function.json file is in this documentation: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-warmup?tabs=csharp-script

kaibocai commented 2 years ago

resolved by https://github.com/Azure/azure-functions-java-library/pull/183

example like:

@FunctionName("Warmup")
public void warmup(@CustomBinding(direction = "in", name = "warmupContext", type = "warmupTrigger")Object warmupContext, ExecutionContext context) {
    context.getLogger().info("Function App instance is warm up");
}