Dev Services Overview
What Are Dev Services?
Quarkus 支持在开发和测试模式下自动配置未配置的服务。我们将此功能称为开发服务。如果您包括一个扩展并且未对其配置,那么 Quarkus 将自动启动相关服务(通常在幕后使用 Testcontainers)并将应用链接起来以使用此服务。
Quarkus supports the automatic provisioning of unconfigured services in development and test mode. We refer to this capability as Dev Services. If you include an extension and don’t configure it then Quarkus will automatically start the relevant service (usually using Testcontainers behind the scenes) and wire up your application to use this service.
有关如何开始编写具有持久性和开发功能的应用程序的分步指南,请参阅 Your Second Quarkus Application。
For a tutorial showing how to get started writing an application with persistence and Dev Services, see Your Second Quarkus Application.
Using Dev Services
开发服务被设计为无摩擦服务,因此只要您未配置连接到外部服务的连接,它们将在您包含支持开发服务的扩展时自动启动。
Dev Services are designed to be frictionless, so they will be automatically started any time you include an extension which supports Dev Services, as long as you don’t configure a connection to an external service.
为了使用大多数开发服务,您需要一个有效的容器环境(支持远程环境)。如果您没有安装容器环境(例如 Docker 或 Podman),您将需要正常配置服务。 |
In order to use most Dev Services you will need a working container environment (remote environments are supported). If you don’t have a container environment, such as Docker or Podman, installed you will need to configure your services normally. |
开发服务的默认启动超时为 60 秒,如果不够,您可使用 quarkus.devservices.timeout
属性增加该超时。
The default startup timeout for Dev Services is 60s, if this is not enough you can increase it with the quarkus.devservices.timeout
property.
要配置生产服务,但在开发和测试模式下继续使用开发服务,请使用 configuration profiles。
To configure a production service but continue to use Dev Services in development and test modes, use configuration profiles.
例如,
For example,
# configure your datasource
%prod.quarkus.datasource.db-kind = postgresql
%prod.quarkus.datasource.username = prod-admin
%prod.quarkus.datasource.password = super-secret
%prod.quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/mydatabase
Disabling Dev Services
所有这些功能都是 Quarkus deployment
模块的一部分,所以不会以任何方式影响生产应用程序。如果您想禁用所有开发服务,则可以使用 quarkus.devservices.enabled=false
配置属性,但在大多数情况下这是没有必要的,因为简单地配置服务就会导致开发服务自动禁用。
All this functionality is part of the Quarkus deployment
modules, so does not affect the production application in any
way. If you want to disable all Dev Services you can use the quarkus.devservices.enabled=false
config property, although
in most cases this is not necessary as simply configuring the service will result in the Dev Service being disabled automatically.
Platform Dev Services
本节列出了 Quarkus 平台中提供的所有开发服务。
This section lists all the Dev Services available in the Quarkus Platform.
AMQP
当 quarkus-messaging-amqp
扩展出现在您的应用程序中,且代理地址尚未被明确配置时,AMQP 开发服务将被启用。更多信息可在 AMQP Dev Services Guide 中找到。
The AMQP Dev Service will be enabled when the quarkus-messaging-amqp
extension is present in your application, and
the broker address has not been explicitly configured. More information can be found in the
AMQP Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-messaging-amqp_quarkus.amqp.devservices.adoc[]
Apicurio Registry
如果扩展`quarkus-apicurio-registry-avro`存在于您的应用程序中,并且尚未明确配置其地址时,Apicurio Dev Service 将被启用。有关更多信息,请参阅Apicurio Registry Dev Services Guide。
The Apicurio Dev Service will be enabled when the quarkus-apicurio-registry-avro
extension is present in your application, and it’s
address has not been explicitly configured. More information can be found in the
Apicurio Registry Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-schema-registry-devservice_quarkus.apicurio-registry.devservices.adoc[]
Databases
如果响应式或 JDBC 数据源扩展存在于应用程序中,并且尚未配置数据库 URL 时,数据库 Dev Services 将被启用。有关更多信息,请参阅Databases Dev Services Guide。
The database Dev Services will be enabled when a reactive or JDBC datasource extension is present in the application, and the database URL has not been configured. More information can be found in the Databases Dev Services Guide.
Quarkus 为其支持的所有数据库提供 Dev Services。除了在进程内运行的 H2 和 Derby 之外,其中大部分都在容器中运行。Dev Services 支持 JDBC 和响应式驱动程序。
Quarkus provides Dev Services for all databases it supports. Most of these are run in a container, except H2 and Derby which are run in-process. Dev Services are supported for both JDBC and reactive drivers.
使用 Testcontainers 启动在容器中运行的那些关系型数据库,并支持“可重用实例”。这意味着如果您在 Testcontainers 配置文件中添加了属性 testcontainers.reuse.enable=true
、在用户主目录中添加名为 .testcontainers.properties
的属性文件,则每次运行后,数据库不会被强制停止,并且可以被重用。
Those relational databases that are running in a container are started using Testcontainers and support "reusable instances";
this implies that if you add the property testcontainers.reuse.enable=true
in your Testcontainers configuration file,
a property file named .testcontainers.properties
in your user home, then the databases will not be stopped aggressively
after each run, and can be reused.
注意:如果您选择此特性,Quarkus 不会在每次运行之间重置数据库的状态,除非您明确进行配置。
N.B. if you opt in for this feature, Quarkus will not reset the state of the database between runs unless you explicitly configure it to.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-datasource_quarkus.datasource.devservices.adoc[]
Kafka
如果扩展`quarkus-kafka-client`存在于您的应用程序中,并且尚未明确配置代理地址时,Kafka Dev Service 将被启用。有关更多信息,请参阅Kafka Dev Services Guide。
The Kafka Dev Service will be enabled when the quarkus-kafka-client
extension is present in your application, and
the broker address has not been explicitly configured. More information can be found in the
Kafka Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-kafka-client_quarkus.kafka.devservices.adoc[]
Keycloak
如果扩展`quarkus-oidc`存在于您的应用程序中,并且尚未明确配置服务器地址时,Keycloak Dev Service 将被启用。有关更多信息,请参阅OIDC Dev Services Guide。
The Keycloak Dev Service will be enabled when the quarkus-oidc
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
OIDC Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-oidc_quarkus.keycloak.devservices.adoc[]
Kubernetes
如果扩展`kubernetes-client`存在于您的应用程序中,并且尚未明确配置 API 服务器地址时,Kubernetes Dev Service 将被启用。有关更多信息,请参阅Kubernetes Dev Services Guide。
The Kubernetes Dev Service will be enabled when the kubernetes-client
extension is present in your application, and
the API server address has not been explicitly configured. More information can be found in the
Kubernetes Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-kubernetes-client_quarkus.kubernetes-client.devservices.adoc[]
MongoDB
如果扩展`quarkus-mongodb-client`存在于您的应用程序中,并且尚未明确配置服务器地址时,MongoDB Dev Service 将被启用。有关更多信息,请参阅MongoDB Guide。
The MongoDB Dev Service will be enabled when the quarkus-mongodb-client
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
MongoDB Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-mongodb-client_quarkus.mongodb.devservices.adoc[]
RabbitMQ
如果扩展`quarkus-messaging-rabbitmq`存在于您的应用程序中,并且尚未明确配置代理地址时,RabbitMQ Dev Service 将被启用。有关更多信息,请参阅RabbitMQ Dev Services Guide。
The RabbitMQ Dev Service will be enabled when the quarkus-messaging-rabbitmq
extension is present in your application, and
the broker address has not been explicitly configured. More information can be found in the
RabbitMQ Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-messaging-rabbitmq_quarkus.rabbitmq.devservices.adoc[]
Pulsar
如果扩展`quarkus-messaging-pulsar`存在于您的应用程序中,并且尚未明确配置代理地址时,Pulsar Dev Service 将被启用。有关更多信息,请参阅Pulsar Dev Services Guide。
The Pulsar Dev Service will be enabled when the quarkus-messaging-pulsar
extension is present in your application, and
the broker address has not been explicitly configured. More information can be found in the
Pulsar Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-messaging-pulsar_quarkus.pulsar.devservices.adoc[]
Redis
Redis Dev 服务将在应用程序中出现 quarkus-redis-client
扩展时启用,并且尚未明确配置服务器地址。有关详细信息,请参阅 Redis Dev Services Guide。
The Redis Dev Service will be enabled when the quarkus-redis-client
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
Redis Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-redis-client_quarkus.redis.devservices.adoc[]
Vault
Vault Dev 服务将在应用程序中出现 quarkus-vault
扩展时启用,并且尚未明确配置服务器地址。有关详细信息,请参阅 Vault Guide。
The Vault Dev Service will be enabled when the quarkus-vault
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
Vault Guide.
Infinispan
Infinispan Dev 服务将在应用程序中出现 quarkus-infinispan-client
扩展时启用,并且尚未明确配置服务器地址。有关详细信息,请参阅 Infinispan Dev Services Guide。
The Infinispan Dev Service will be enabled when the quarkus-infinispan-client
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
Infinispan Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-infinispan-client_quarkus.infinispan-client.devservices.adoc[]
Elasticsearch
Elasticsearch Dev 服务将在应用程序中出现基于 Elasticsearch 的扩展之一(Elasticsearch 客户端或 Hibernate Search ORM Elasticsearch)时启用,并且尚未明确配置服务器地址。有关详细信息,请参阅 Elasticsearch Dev Services Guide。
The Elasticsearch Dev Service will be enabled when one of the Elasticsearch based extensions (Elasticsearch client or Hibernate Search ORM Elasticsearch) is present in your application, and the server address has not been explicitly configured. More information can be found in the Elasticsearch Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-elasticsearch-rest-client_quarkus.elasticsearch.devservices.adoc[]
Observability
Observability Dev 服务将在应用程序中出现 quarkus-observability-devservices
扩展时启用,并且类路径上至少有一个开发资源。有关详细信息,请参阅 Observability Dev Services Guide。
The Observability Dev Services will be enabled when the quarkus-observability-devservices
extension is present in your application, and
there is at least one dev resource on the classpath. More information can be found in the
Observability Dev Services Guide.
Unresolved directive in dev-services.adoc - include::{generated-dir}/config/quarkus-observability-devservices.adoc[]
Dev Services beyond the Quarkus Platform
Quarkiverse 中许多不在 Quarkus Platform 中的扩展还提供 Dev 服务。
Many Quarkiverse extensions which are not in the Quarkus Platform also offer Dev Services.
以下是一些重点。
Here are some highlights.
Neo4j
Neo4j Dev 服务将在应用程序中出现 quarkus-neo4j
扩展时启用,并且尚未明确配置服务器地址。有关详细信息,请参阅 Neo4j Guide。
The Neo4j Dev Service will be enabled when the quarkus-neo4j
extension is present in your application, and
the server address has not been explicitly configured. More information can be found in the
Neo4j Guide.
WireMock
WireMock 扩展将 WireMock 作为 Dev 服务启动。它是一个以测试为重点的扩展,旨在仅在开发和测试模式下运行。有关详细信息,请参阅 WireMock Guide。
The WireMock extension starts WireMock as a Dev Service. It is a test-focussed extension, designed to run in dev and test mode only. More information can be found in the WireMock Guide.
Microcks
Microcks Quarkus 扩展包含 Microcks Dev 服务。Dev 服务管理依赖项的模拟和对 API 端点的契约测试。有关详细信息,请参阅扩展 README.md。
The Microcks Quarkus extension includes a Microcks Dev Service. The Dev Service manages mocks for dependencies and contract-testing your API endpoints. See the extension README.md for more information.