The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.
このページを編集

MongoDBのDev Services

QuarkusはDev Servicesという機能をサポートしており、設定なしでさまざまなデータソースを作成できます。MongoDBの場合、このサポートはデフォルトのMongoDB接続にまで及びます。 つまり、 quarkus.mongodb.connection-stringquarkus.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: QUARKUS_MONGODB_DEVSERVICES_ENABLED

Show more

ブーリアン

The container image name to use, for container based DevServices providers.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_IMAGE_NAME

Show more

string

docker.io/library/mongo:7.0

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_PORT

Show more

int

Generic properties that are added to the connection URL.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_PROPERTIES__PROPERTY_KEY_

Show more

Map<String,String>

Environment variables that are passed to the container.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_CONTAINER_ENV__ENVIRONMENT_VARIABLE_NAME_

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 quarkus-dev-service-mongodb label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_SHARED

Show more

ブーリアン

true

The value of the quarkus-dev-service-mongodb label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services for MongoDB looks for a container with the quarkus-dev-service-mongodb label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise it starts a new container with the quarkus-dev-service-mongodb label set to the specified value.

Environment variable: QUARKUS_MONGODB_DEVSERVICES_SERVICE_NAME

Show more

string

mongodb