The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Azure Functions with Quarkus REST, Undertow, or Reactive Routes

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.

この技術は、previewと考えられています。

preview では、下位互換性やエコシステムでの存在は保証されていません。具体的な改善には設定や API の変更が必要になるかもしれませんが、 stable になるための計画は現在進行中です。フィードバックは メーリングリストGitHub の課題管理 で受け付けています。

とりうるステータスの完全なリストについては、 FAQの項目 を参照してください。

Azure Functions HTTP Trigger for Javaがバイナリ形式をサポートしていないため、現時点ではテキストベースのメディアタイプのみがサポートされています

前提条件

このガイドを完成させるには、以下が必要です:

ソリューション

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.

Maven/Gradleプロジェクトの作成

You can generate the example code from Quarkus’s online application generator at this link.

この例は、Quarkus CLIで生成することもできます:

quarkus create app --extension=quarkus-azure-functions-http

gradleプロジェクトを生成したい場合は、 --gradle スイッチを追加します。

Azureへのログイン

Azureにログインしないとデプロイできません。

az login

Quarkus dev mode

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

プロジェクトの確認

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.

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.

Build configuration is now all within application.properties. The only required configuration switch is quarkus.azure-functions.app-name.

Azureデプロイメントディスクリプタ

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.

ルートパスの設定

Azure Functionのデフォルトのルートプレフィックスは、 /api です。Jakarta REST、Servlet、Reactive Routes、Funqy HTTP のすべてのエンドポイントでは、これを明示的に考慮する必要があります。生成されたプロジェクトでは、 application.properties 内の quarkus.http.root-path のスイッチによって処理されます。

Azureへのログイン

Azureにログインしないとデプロイできません。

az login

Quarkus dev mode

Quarkusの開発モードは、現在Azure Functionsでは動作しません。

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 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.

なお、これを実行するためには、 Azure Functions Core Tools がインストールされている必要があります!

例題にアクセスするためのURLは次のようになります:

Quarkus統合テスト

@QuarkusIntegrationTest の機能を使用して統合テストを実装できます。これらの統合テストが実行されると、統合テストの間、ローカルの Azure Functions 環境がスピンアップされます。

Mavenの場合:

./mvnw -DskipITs=false verify

maven で実行する統合テストが *IT.java ファイルパターンを使用しているようにし、通常のビルドでテストが実行されないようにします。

Gradleの場合:

./gradlew --info quarkusIntTest

Gradle で実行する統合テストが src/integrationTest/java 内にあることを確認してください。 src/test に存在する統合テストは通常のビルドで実行され、失敗します。

Azureへのデプロイ

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.

デプロイを実行するには、プロジェクトをビルドした後、次のコマンドを実行してください:

./mvnw quarkus:deploy

or

./gradlew --info deploy

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!

例えば

[INFO] HTTP Trigger Urls:
[INFO] 	 HttpExample : https://{appName}.azurewebsites.net/api/{*path}

The URL to access the service would be something like

関連コンテンツ