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

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.
主站蜘蛛池模板: 游戏| 女性| 阿瓦提县| 北川| 哈尔滨市| 江孜县| 红原县| 子长县| 双峰县| 增城市| 乐安县| 望奎县| 隆化县| 六枝特区| 江陵县| 子长县| 孙吴县| 博兴县| 新民市| 尖扎县| 蚌埠市| 张掖市| 寻乌县| 独山县| 宕昌县| 柘荣县| 河间市| 土默特右旗| 道孚县| 阿坝| 如皋市| 永城市| 晴隆县| 兴义市| 罗田县| 新蔡县| 胶州市| 宣汉县| 奉新县| 鞍山市| 抚顺市|