Azure Functions with Quarkus REST, Undertow, or Reactive Routes
quarkus-azure-functions-http
扩展允许您使用 Quarkus REST(我们的 Jakarta REST 实现)、Undertow(servlet)、Reactive Routes 或 Funqy HTTP 编写微服务,并使这些微服务能够部署到 Azure Functions 运行时。换句话说,此扩展是 Azure Functions HttpTrigger 和 Quarkus 系列 HTTP API 之间的桥梁。Azure 函数部署可以表示任意数量的 Jakarta REST、servlet、Reactive Routes 或 Funqy HTTP 端点。
The quarkus-azure-functions-http
extension allows you to write microservices with Quarkus REST (our Jakarta REST implementation),
Undertow (servlet), Reactive Routes, or Funqy HTTP and make these microservices deployable to the Azure Functions runtime.
In other words, this extension is a bridge from the Azure Functions HttpTrigger and the Quarkus family
of HTTP APIs.
One azure function deployment can represent any number of Jakarta REST, servlet, Reactive Routes, or Funqy HTTP endpoints.
Unresolved directive in azure-functions-http.adoc - include::{includes}/extension-status.adoc[]
目前只支持基于文本的媒体类型,因为 Azure Functions Java 的 HTTP 触发器不支持二进制格式。 |
Only text based media types are supported at the moment as Azure Functions HTTP Trigger for Java does not support a binary format |
Prerequisites
Unresolved directive in azure-functions-http.adoc - include::{includes}/prerequisites.adoc[]* An Azure Account。免费帐户有效。* Azure Functions Core Tools 版本 4.x* Azure CLI Installed
Unresolved directive in azure-functions-http.adoc - include::{includes}/prerequisites.adoc[] * An Azure Account. Free accounts work. * Azure Functions Core Tools version 4.x * Azure CLI Installed
Solution
本指南将指导您逐步运行一个 Maven 项目,该项目可以将 Quarkus REST 端点部署到 Azure Functions。虽然只提供 Jakarta REST 作为示例,但您可以轻松地用您选择的 HTTP 框架替换它。
This guide walks you through running a maven project that can deploy a Quarkus REST endpoint to Azure Functions. While only Jakarta REST is provided as an example, you can easily replace it with the HTTP framework of your choice.
Creating the Maven/Gradle Project
您可以在 this link 处的 Quarkus 在线应用程序生成器中生成示例代码。
You can generate the example code from Quarkus’s online application generator at this link.
你还可以使用 Quarkus CLI 生成此示例:
You can also generate this example with the Quarkus CLI:
quarkus create app --extension=quarkus-azure-functions-http
如果你想生成 gradle 项目,请添加 @“1” 开关。
Add the --gradle
switch if you want to generate a gradle project.
Login to Azure
如果你不登录到 Azure,你将无法部署。
If you don’t log in to Azure you won’t be able to deploy.
az login
Quarkus dev mode
Quarkus 开发模式的工作原理只是将其应用程序作为 HTTP 端点运行。在开发模式下,与 Azure Functions 本地运行时没有特殊的交互。
Quarkus dev mode works by just running your application as a HTTP endpoint. In dev mode there is no special interaction with the Azure Functions local runtime.
./mvnw clean package quarkus:dev
Examining the project
如果您打开生成项目的 pom.xml
或 build.gradle
构建文件,您会发现该项目类似于任何其他 Quarkus 项目。quarkus-azure-functions-http
扩展是 Quarkus 和 Azure Functions 之间的集成点。
If you open the pom.xml
or build.gradle
build file of the generated project you’ll see that
the project is similar to any other Quarkus project.
The quarkus-azure-functions-http
extension is the integration point between
Quarkus and Azure Functions.
quarkus-azure-functions-http
扩展的当前实现不再需要 azure-functions-maven-plugin
或等效的 gradle。本地开发和 Azure Functions 打包和部署现在都由 Quarkus 完成。
The current implementation of the quarkus-azure-functions-http
extension no longer requires the
azure-functions-maven-plugin
or gradle equivalent. Local development and Azure Functions packaging and
deployment is now all done by Quarkus.
构建配置现在都在 @“7” 内。唯一必需的配置开关是 @“8”。
Build configuration is now all within application.properties
. The only required configuration switch
is quarkus.azure-functions.app-name
.
Azure Deployment Descriptors
Azure Functions @“9” 部署描述符自动生成,但如果你需要覆盖它,请在项目的根目录中声明它并在准备就绪时重新运行构建。
The Azure Functions host.json
deployment descriptor is automatically
generated, but if you need to override it, declare it in the root directory of the project and
rerun the build when you are ready.
Configuring Root Paths
Azure Functions 的默认路由前缀为 /api
。您的所有 Jakarta REST、Servlet、Reactive Routes 和 Funqy HTTP 端点必须显式考虑这一点。在生成的项目中,这由 application.properties
中的 quarkus.http.root-path
开关处理。
The default route prefix for an Azure Function is /api
. All of your Jakarta REST, Servlet, Reactive Routes, and Funqy HTTP endpoints must
explicitly take this into account. In the generated project this is handled by the
quarkus.http.root-path
switch in application.properties
Login to Azure
如果你不登录到 Azure,你将无法部署。
If you don’t log in to Azure you won’t be able to deploy.
az login
Quarkus dev mode
Quarkus 开发模式当前不适用于 Azure Functions。
Quarkus dev mode does not work currently with Azure Functions.
Run locally in Azure Functions local environment
如果您想在本地 Azure Functions 环境中尝试此示例,可以使用此命令
If you want to try this example within the local Azure Functions environment, you can use this command
./mvnw quarkus:run
或
or
./gradlew --info --no-daemon quarkusRun
Gradle 在进程管理方面有点怪异,所以你需要 @“10” 开关或 ctrl-c 不会干净地销毁进程,你将会有打开的端口。
Gradle is a bit quirky with process management, so you need the --no-daemon
switch or control-c will not
destroy the process cleanly and you’ll have open ports.
请注意,你必须安装 @“11” 才能使此项工作!
Note that you must have the Azure Functions Core Tools installed for this to work!
访问该示例的 URL 为:
The URL to access the example would be:
[role="bare"][role="bare"]http://localhost:8081/api/hello
[role="bare"]http://localhost:8081/api/hello
Quarkus Integration Testing
你可以使用 @“13” 功能实现集成测试。当这些集成测试运行时,本地 Azure Functions 环境将为集成测试期间启动。
You can implement integration tests using @QuarkusIntegrationTest
functionality. When these
integration tests run, the local Azure Functions environment will be spun up for the duration of integration testing.
对于 maven:
For maven:
./mvnw -DskipITs=false verify
确保你使用 maven 执行的任何集成测试都使用 @“14” 文件模式,以便常规构建不执行测试。
Make sure any integration tests you execute with maven use the *IT.java
file pattern so that regular builds do not execute
the test.
对于 Gradle:
For Gradle:
./gradlew --info quarkusIntTest
确保你使用 Gradle 执行的任何集成测试都位于 @“15” 中。存在于 @“16” 中的集成测试将随常规构建一起运行并失败。
Make sure any integration tests you execute with Gradle are located within src/integrationTest/java
. Integration
tests that exist in src/test
will run with normal build and fail.
Deploy to Azure
quarkus-azure-functions-http
扩展处理向 Azure 部署的所有工作。默认情况下,Quarkus 将在后台使用 Azure CLI 对 Azure 进行授权和部署。如果您有多个订阅与您的帐户相关联,您必须将 application.properties
文件中的 quarkus.azure-functions.subscription-id
属性设置为您要使用的订阅。有关其他身份验证机制和部署选项,请参阅我们的配置属性 here。
The quarkus-azure-functions-http
extension handles all the work to deploy to Azure. By default,
Quarkus will use the Azure CLI in the background to authenticate and deploy to Azure. If you have
multiple subscriptions associated with your account, you must set the quarkus.azure-functions.subscription-id
property in your application.properties
file to the subscription you want to use.
For other authentication mechanisms and deployment options see our config properties here.
在构建好项目后,执行以下命令可运行该部署:
To run the deploy, after you build your project execute:
./mvnw quarkus:deploy
或
or
./gradlew --info deploy
如果部署成功,Quarkus 会将示例函数的端点 URL 输出到控制台。对于 Gradle,您必须使用 --info
开关才能看到此输出!
If deployment is a success, Quarkus will output the endpoint URL of the example function to the console
For Gradle, you must use the --info
switch to see this output!
即
i.e.
[INFO] HTTP Trigger Urls:
[INFO] HttpExample : https://{appName}.azurewebsites.net/api/{*path}
访问服务的 URL 类似于
The URL to access the service would be something like
[role="bare"][role="bare"]https://{appName}.azurewebsites.net/api/hello
[role="bare"]https://{appName}.azurewebsites.net/api/hello