Quarkus REST、Undertow、または Reactive Routes を使用した Azure Functions
quarkus-azure-functions-http エクステンションを使用すると、Quarkus REST (Jakarta REST 実装) を使用してマイクロサービスを作成できます。
Undertow (servlet)、Reactive Routes、または Funqy HTTP を使用して、これらのマイクロサービスを Azure Functions ランタイムにデプロイできるようにします。
言い換えれば、このエクステンションは Azure Functions HttpTrigger と HTTP API の Quarkus ファミリーのブリッジとして機能します。
1 つの Azure 関数のデプロイメントは、任意の数の Jakarta REST、サーブレット、Reactive Routes、または Funqy HTTP のエンドポイントを表現できます。
|
この技術は、previewと考えられています。 preview では、下位互換性やエコシステムでの存在は保証されていません。具体的な改善には設定や API の変更が必要になるかもしれませんが、 stable になるための計画は現在進行中です。フィードバックは メーリングリスト や GitHub の課題管理 で受け付けています。 とりうるステータスの完全なリストについては、 FAQの項目 を参照してください。 |
| Azure Functions HTTP Trigger for Javaがバイナリ形式をサポートしていないため、現時点ではテキストベースのメディアタイプのみがサポートされています |
要件
このガイドを完成させるには、以下が必要です:
-
約15分
-
IDE
-
JDK 17+がインストールされ、
JAVA_HOMEが適切に設定されていること -
Apache Maven 3.9.11
-
使用したい場合は、 Quarkus CLI
-
ネイティブ実行可能ファイルをビルドしたい場合、MandrelまたはGraalVM(あるいはネイティブなコンテナビルドを使用する場合はDocker)をインストールし、 適切に設定していること
-
Azureのアカウント 無料アカウントでも大丈夫です。
-
Azure Functions Core Tools バージョン4.x
ソリューション
このガイドでは、Quarkus REST エンドポイントを Azure Functions にデプロイできる maven プロジェクトの実行について説明します。 その例として Jakarta REST が示されていますが、これは簡単に任意の HTTPフレームワークに置き換えることができます。
Maven/Gradleプロジェクトの作成
まず、新しいプロジェクトが必要です。以下のコマンドで新規プロジェクトを作成します:
Windowsユーザーの場合:
-
cmdを使用する場合、(バックスラッシュ
\を使用せず、すべてを同じ行に書かないでください)。 -
Powershellを使用する場合は、
-Dパラメータを二重引用符で囲んでください。例:"-DprojectArtifactId=azure-functions-http-quickstart"
This command generates a project structure importing the Quarkus Azure Functions HTTP extension. It includes an example.
プロジェクトの確認
生成されたプロジェクトの pom.xml または build.gradle ビルドファイルを開くと、
このプロジェクトは他の Quarkus プロジェクトと同様であることがわかります。
quarkus-azure-functions-http エクステンションは、
Quarkus と 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 all within application.properties. The only required configuration switch
is quarkus.azure-functions.app-name.
Azureデプロイメントディスクリプタ
Azure Functions の`host.json`デプロイメント記述子は自動的に 生成されますが、オーバーライドする必要がある場合は、プロジェクトの root ディレクトリーで宣言し、 準備ができたらビルドを再実行します。
ルートパスの設定
Azure Functionのデフォルトのルートプレフィックスは、/api です。Jakarta REST、Servlet、Reactive Routes、Funqy HTTP のすべてのエンドポイントでは、これを明示的に考慮する必要があります。生成されたプロジェクトでは、application.properties 内の quarkus.http.root-path のスイッチによって処理されます。
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.
quarkus dev
./mvnw quarkus:dev
./gradlew --console=plain quarkusDev
Azure Functionsローカル環境での実行
If you want to try this example within the local Azure Functions environment, you can use this command:
quarkus run
./mvnw quarkus:run
./gradlew --console=plain --info --no-daemon quarkusRun
|
Gradle はプロセス管理に少しクセがあるため、 |
|
You must have the Azure Functions Core Tools installed for this to work. |
例題にアクセスするためのURLは次のようになります:
Quarkus統合テスト
@QuarkusIntegrationTest の機能を使用して統合テストを実装できます。これらの統合テストが実行されると、
統合テストの間、ローカルの Azure Functions 環境がスピンアップされます。
./mvnw verify
./gradlew --info quarkusIntTest
|
Make sure any integration tests you execute with Maven use the |
|
Gradle で実行する統合テストが |
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 Azure Functions Configuration Reference.
To deploy your application, after you built your project, execute:
./mvnw quarkus:deploy
./gradlew --info deploy
|
For Gradle, you must use the |
If deployment is a success, Quarkus will output the endpoint URL of the example function to the console:
[INFO] HTTP Trigger Urls:
[INFO] HttpExample : https://{appName}.azurewebsites.net/api/{*path}
The URL to access the service would be something like: https://{appName}.azurewebsites.net/api/hello.
Azure Functions Configuration Reference
ビルド時に固定される設定プロパティ - 他のすべての設定プロパティは実行時にオーバーライド可能
Configuration property |
タイプ |
デフォルト |
|---|---|---|
App name for azure function project. This is required setting. Defaults to the base artifact name Environment variable: Show more |
string |
|
Azure Resource Group for your Azure Functions Environment variable: Show more |
string |
|
Specifies the region where your Azure Functions will be hosted; default value is westus. Valid values Environment variable: Show more |
string |
|
Specifies whether to disable application insights for your function app Environment variable: Show more |
boolean |
|
Specifies the instrumentation key of application insights which will bind to your function app Environment variable: Show more |
string |
|
Valid values are linux, windows, and docker Environment variable: Show more |
string |
|
Should be set to at least the minimum Quarkus compatible version Environment variable: Show more |
string |
|
URL of docker image if deploying via docker Environment variable: Show more |
string |
|
If using docker, url of registry Environment variable: Show more |
string |
|
Description of each type can be found here Valid values are
Defaults to "azure_cli" for authentication Environment variable: Show more |
string |
|
Filesystem path to properties file if using file type Environment variable: Show more |
string |
|
Client or App Id required if using managed_identity type Environment variable: Show more |
string |
|
Tenant ID required if using oauth2 or device_code type Environment variable: Show more |
string |
|
Specifies the name of the existing App Service Plan when you do not want to create a new one. Environment variable: Show more |
string |
|
The app service plan resource group. Environment variable: Show more |
string |
|
Azure subscription id. Required only if there are more than one subscription in your account Environment variable: Show more |
string |
|
The pricing tier. Environment variable: Show more |
string |
|
Port to run azure function in local runtime. Will default to quarkus.http.test-port or 8081 Environment variable: Show more |
int |
|
Config String for local debug Environment variable: Show more |
string |
|