官术网_书友最值得收藏!

Azure Functions and Java

Despite the fact that the Azure Functions Runtime supports Java, you cannot create a Java Azure Function using the Azure Function Core Tool in the same way that you created a JavaScript function in the previous section.

To create a Java Azure Function you need the Azure Function Core Tools, but you also must have the following:

The process to create a Java Azure Function is not simple and linear, but in the end, a Java Azure Function is a public method decorated with the @FunctionName annotation (as the FunctionName attribute for the C# functions). This method is the entry point for the function and it must be unique in the entire package.

The structure of a project written in Java that contains an Azure Function resembles the following:

The target folder contains the binaries of the functions, that is, the set of files to deploy.

The host.json file is used, as it is for the C# and Node.js functions, to configure the function app and to define the extensions you want to use inside your functions. Each function has its folder (with the same name as the function), in which you will find the function.json file that contains the definition of the bindings, as shown in the following code:

{
"scriptFile": "myFirstJavaFunction.jar",
"entryPoint": "com.example.Function.httpTriggerFunction",
"bindings": [
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"authLevel": "function",
"methods": [ "get" ]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
]
}

The previous function.json corresponds to the function, as shown in the following code:

public class Function {
@FunctionName("httpTriggerFunction")
public String httpTriggerFunction(@HttpTrigger(name = "req", methods = {"get"}, authLevel = AuthorizationLevel.FUNCTION) String req,
ExecutionContext context)
{
return String.format(req);
}
}

As you can see in the previous function, one of the arguments is an instance of ExecutionContext. It is similar to the context you saw in the Node.js paragraph. It allows you to access log features.

If you want to host your Java functions locally, you have to use Maven, and in particular, you need to run the following commands inside the root folder of your function project:

mvn clean package 
mvn myFirstJavaFunction:run
You can find more info about Java Azure Function development in the official documentation at https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven. You can find the developer guide reference at https://docs.microsoft.com/en-us/java/api/overview/azure/functions/readme?view=azure-java-stable.
主站蜘蛛池模板: 商洛市| 柞水县| 轮台县| 满城县| 石渠县| 台前县| 灯塔市| 汽车| 大方县| 瑞安市| 灵石县| 三穗县| 宿松县| 唐山市| 嵩明县| 固原市| 望城县| 葫芦岛市| 北川| 彰武县| 南丰县| 安图县| 克东县| 华坪县| 临夏市| 右玉县| 黄山市| 冀州市| 石景山区| 葫芦岛市| 陆丰市| 长治市| 沂南县| 竹北市| 南汇区| 平乐县| 玉龙| 丘北县| 仙桃市| 台安县| 岳普湖县|