MongoDBのDev Services
QuarkusはDev Servicesという機能をサポートしており、設定なしでさまざまなデータソースを作成できます。MongoDBの場合、このサポートはデフォルトのMongoDB接続にまで及びます。
つまり、 quarkus.mongodb.connection-string や quarkus.mongodb.hosts を設定していない場合、Quarkus はテストの実行中や開発モードのときに自動的に MongoDB コンテナを起動し、自動的に接続を設定します。
MongoDB Dev Servicesは Testcontainers MongoDBモジュール をベースにしており、単一ノードのレプリカセットを起動することができます。
本番環境のアプリケーションを実行する場合、MongoDBの接続は通常通りに設定する必要があります。本番環境のデータベースの設定を application.properties に含めてDev Servicesを継続して使用する場合は、 %prod. プロファイルを使用してMongoDBの設定を定義することをお勧めします。
共有サーバー
ほとんどの場合、アプリケーション間でサーバーを共有する必要があります。 Dev Services for MongoDBは、 dev モードで実行されている複数のQuarkusアプリケーションが1つのサーバーを共有できるように、 サービス検出 メカニズムを実装しています。
Dev Services for MongoDB はコンテナを識別するための quarkus-dev-service-mongodb ラベルでコンテナを起動します。
|
複数の(共有)サーバーが必要な場合は、 quarkus.mongodb.devservices.service-name 属性を設定し、サーバー名を指定します。
同じ値を持つコンテナを探すか、見つからない場合は新しいコンテナを起動します。デフォルトのサービス名は mongodb です。
共有はdevモードではデフォルトで有効ですが、testモードでは無効になります。共有は quarkus.mongodb.devservices.shared=false で無効にできます。
Compose
MongoDB Dev Services は Compose Dev Services をサポートしています。
これは compose-devservices.yml に依存しています:
name: <application name>
services:
mongo:
image: docker.io/library/mongo:7.0
ports:
- "27017"
設定リファレンス
ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。
Configuration property |
タイプ |
デフォルト |
|---|---|---|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode. Environment variable: Show more |
ブーリアン |
|
The container image name to use, for container based DevServices providers. Environment variable: Show more |
string |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: Show more |
int |
|
Generic properties that are added to the connection URL. Environment variable: Show more |
Map<String,String> |
|
Environment variables that are passed to the container. Environment variable: Show more |
Map<String,String> |
|
Indicates if the MongoDB server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for MongoDB starts a new container. The discovery uses the Container sharing is only used in dev mode. Environment variable: Show more |
ブーリアン |
|
The value of the Environment variable: Show more |
string |
|