Azure Functions (Serverless) with RESTEasy Reactive, Undertow, or Reactive Routes
The quarkus-azure-functions-http
extension allows you to write microservices with RESTEasy Reactive (JAX-RS), Undertow (servlet), Reactive Routes, or Funqy HTTP and make these microservices deployable to the Azure Functions runtime.
One azure function deployment can represent any number of JAX-RS, servlet, Reactive Routes, or Funqy HTTP endpoints.
この技術は、previewと考えられています。 preview では、下位互換性やエコシステムでの存在は保証されていません。具体的な改善には設定や API の変更が必要になるかもしれませんが、 stable になるための計画は現在進行中です。フィードバックは メーリングリスト や GitHub の課題管理 で受け付けています。 For a full list of possible statuses, check our FAQ entry. |
Azure Functions HTTP Trigger for Javaがバイナリ形式をサポートしていないため、現時点ではテキストベースのメディアタイプのみがサポートされています。 |
前提条件
このガイドを完成させるには、以下が必要です:
-
約15分
-
IDE
-
JDK 11+ がインストールされ、
JAVA_HOME
が適切に設定されていること -
Apache Maven 3.8.1+
-
使用したい場合、 Quarkus CLI
-
ネイティブ実行可能ファイルをビルドしたい場合、MandrelまたはGraalVM(あるいはネイティブなコンテナビルドを使用する場合はDocker)をインストールし、 適切に設定していること
-
Azureのアカウント 。無料アカウントでも大丈夫です。
ソリューション
このガイドでは、JAX-RS API、Servlet API、Vert.x Web、または Funqy HTTP APIで記述された3つのHTTPエンドポイントを含むサンプルプロジェクトを生成するために、Maven Archetype のウォークスルーを行います。ビルド後、Azureにデプロイできるようになります。
Maven デプロイメントプロジェクトの作成
Maven Archetypeを使用して、Quarkusアプリケーション用の Azure mavenプロジェクトを作成します。
mvn archetype:generate \
-DarchetypeGroupId=io.quarkus \
-DarchetypeArtifactId=quarkus-azure-functions-http-archetype \
-DarchetypeVersion=2.11.1.Final
このコマンドを実行すると、インタラクティブモードでmavenが実行され、いくつかのビルドプロパティーの入力を求められます。
-
groupId
- この生成されたプロジェクトの maven グループ ID。org.acme
と入力します。 -
artifactId
- この生成されたプロジェクトの maven artifactId。を入力します。quarkus-demo
と入力します。 -
version
- この生成されたプロジェクトのバージョン。 -
package
- デフォルトはgroupId
-
appName
- Use the default value. This is the application name in Azure. It must be a unique subdomain name under*.azurewebsites.net
. Otherwise, deploying to Azure will fail. -
appRegion
- デフォルトはwestus
です。お使いの azure リージョンに依存します。 -
function
- デフォルトのquarkus
を使用してください。あなたの azure 関数の名前。何でも構いません。 -
resourceGroup
- デフォルト値を使用してください。どんな値でも構いません。
上記の値は、生成された pom.xml
ファイルのプロパティーとして定義されています。
ビルドと Azure へのデプロイ
前のステップで生成した pom.xml
は、 azure-functions-maven-plugin
.maven install を実行すると、設定ファイルと azure-functions-maven-plugin
によって必要とされるステージングディレクトリーが生成されます。実行方法は以下の通りです。
./mvnw clean install azure-functions:deploy
If you haven’t already created your function up at azure, then build an uber-jar, package it, create the function at Azure, and deploy it.
デプロイが成功した場合、azure プラグインは Function にアクセスするためのベース URL を教えてくれます。
例えば
Successfully deployed the artifact to https://quarkus-demo-123451234.azurewebsites.net
サービスにアクセスするためのURLは次のようになります。
エクステンションのmaven依存関係
The sample project includes the RESTEasy Reactive, Undertow, Reactive Routes, Funqy HTTP extensions. If you are only using one of those APIs (i.e. jax-rs only), respectively remove the maven dependency quarkus-resteasy-reactive
, quarkus-undertow
, quarkus-funqy-http
, and/or quarkus-reactive-routes
.
quarkus-azure-functions-http
エクステンションを含める必要があります。これは、Azure Functions ランタイムとマイクロサービスを書いている HTTP フレームワークの間の一般的なブリッジです。
Azureデプロイメントディスクリプタ
Azure Functions デプロイメントディスクリプタのテンプレート ( host.json
, function.json
) は、 azure-config
ディレクトリー内にあります。必要に応じて編集してください。準備ができたらビルドを再実行します。
注 : function.json
path
属性を変更したり、 routePrefix
を追加したりすると、jax-rs エンドポイントは正しくルーティングされません。詳細は [config-azure-paths ] を参照してください。
ルートパスの設定
The default route prefix for an Azure Function is /api
. All of your JAX-RS, 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
path
を変更したり、 azure-config/function.json
デプロイメントディスクリプタ内に routePrefix
を追加したりする場合、コードや設定にはパスに指定した接頭辞も反映させる必要があります。