Dev Services for Infinispan

Quarkus 支持一个名为开发服务的功能,它允许你在没有任何配置的情况下创建各种数据源。如果你正在运行 docker 且没有配置 quarkus.infinispan-client.hosts,那么在运行测试或开发模式时,Quarkus 将自动启动一个 Infinispan 容器,并自动配置连接。

Quarkus supports a feature called Dev Services that allows you to create various datasources without any config. If you have docker running and have not configured quarkus.infinispan-client.hosts, Quarkus will automatically start an Infinispan container when running tests or dev mode, and automatically configure the connection.

以下属性可用于定制 Infinispan 开发服务:

The following properties are available to customize the Infinispan Dev Services: Unresolved directive in infinispan-dev-services.adoc - include::{generated-dir}/config/quarkus-infinispan-client_quarkus.infinispan-client.devservices.adoc[]

在运行应用程序的生产版本时,Infinispan 连接需要正常配置,所以如果你想在 `application.properties`中包含一个生产数据库配置并继续使用开发服务,我们建议你使用 `%prod.`配置概况来定义你的 Infinispan 设置。

When running the production version of the application, the Infinispan connection need to be configured as normal, so if you want to include a production database config in your application.properties and continue to use Dev Services we recommend that you use the %prod. profile to define your Infinispan settings.

Infinispan 的开发服务依赖于 Docker 来启动服务器。

Dev Services for Infinispan relies on Docker to start the server.

Connecting to the running Infinispan Server

don’t need to configure anything in dev mode.服务器将在一个随机端口运行。如果你需要一个固定端口,那就配置 `quarkus.infinispan-client.devservices.port`属性。

You don’t need to configure anything in dev mode. The server will be running in a random port. If you need a fixed port, then configure quarkus.infinispan-client.devservices.port property.

运行的 Infinispan 服务器启用了身份验证,并拥有完全管理员角色的一个用户。该用户的凭证为 admin/password

The running Infinispan Server has authentication enabled and a user with full admin role. The credentials of the user are admin/password.

Accessing to the Infinispan Server Console

Infinispan 服务器提供了一个可以用浏览器访问的 Web 控制台:

Infinispan Server provides a web console that can be accessed with a browser:

  1. Open the Dev UI

  2. You will see an Infinispan Client box. Click on Web Console and enter the credentials above.

dev ui infinispan

如果你的环境不支持 Docker,你将需要手动启动一个 Infinispan 服务器,或连接到一个正在运行的服务器。

If your environment does not support Docker, you will need to spin up an Infinispan Server manually, or connect to an already running server.

Overriding the Infinispan Server Image

该扩展定期更新,并且开发服务将启动 Infinispan 的最新最终版本映像。使用 `quarkus.infinispan-client.devservices.image-name`属性来指定另一个适合你需要的图像。

The extension is updated regularly and the Dev Services will start the latest final version image of Infinispan. Use quarkus.infinispan-client.devservices.image-name property to specify another image that fits your needs.

Enabling / Disabling Dev Services for Infinispan

除非满足以下条件,否则 Infinispan 的开发服务将自动启用:

Dev Services for Infinispan is automatically enabled unless:

  • quarkus.infinispan-client.devservices.enabled is set to false

  • the quarkus.infinispan-client.hosts is configured

Dev Services for Infinispan 依赖于 Docker 来启动代理。如果您的环境不支持 Docker,您将需要手动启动代理,或连接到已经运行的代理。您可以使用 `quarkus.infinispan-client.hosts`来配置代理地址。

Dev Services for Infinispan relies on Docker to start the broker. If your environment does not support Docker, you will need to start the broker manually, or connect to an already running broker. You can configure the broker address using quarkus.infinispan-client.hosts.

Providing configuration to the running server

Dev Services for Infinispan 将默认启动带 infinispan.xml 文件的 Infinispan。但是,在某些情况下,向服务器提供一些额外的配置会有帮助。这可以通过在资源类路径中添加 xml、yaml 或 json 配置文件并提供以下配置来完成:

Dev Services for Infinispan will spin up an Infinispan with the infinispan.xml file by default. However, there are cases where is helpful to provide some extra configuration to the server. This can be done by adding configuration files in xml, yaml or json to the resources classpath and providing the following configuration:

quarkus.infinispan-client.devservices.config-files=server-config-override.xml 1
1 server-config-override.xml is a file under the resources folder
<infinispan> 1
    <cache-container>
        <local-cache name="my-local-cache"> 2
            <encoding media-type="application/x-protostream" />
        </local-cache>
    </cache-container>
</infinispan>
1 The content of server-config-override.xml file
2 By providing a cache configuration, this cache will be present on the server container

Cross Site Replication

如果您想使用跨站点复制配置运行 Infinispan 服务器容器,您需要提供一个站点名称。

If you want run the Infinispan Server container with Cross Site Replication configuration, you need to provide a site name.

quarkus.infinispan-client.devservices.site=NYC 1
quarkus.infinispan-client.devservices.mcast-port=46666 2
1 Provides a site name for your Infinispan cluster
2 Eventually configure a mcastPort if you want to avoid creating a cluster with another container

在 Infinispan 跨站点复制 documentation guide和 Infinispan 跨站点复制 simple code tutorial中了解有关跨站点复制的更多信息。

Learn more about Cross Site Replication in the Infinispan Cross Site Replication documentation guide and in the Infinispan Cross Site Replication simple code tutorial.

Multiple Dev Services for named connections

Infinispan 客户端扩展支持使用命名连接连接到多个 Infinispan 集群。如果您需要为连接名称增加一个 dev 服务,请至少在应用程序属性中配置一个属性:

The Infinispan Client extension supports connecting to more than one Infinispan Cluster with the named connections. If you need to spin an additional dev service for a connection name, configure at least on property in the application properties:

quarkus.infinispan-client.conn-2.devservices.enabled=true

Tracing with OpenTelemetry

Infinispan 使用 OpenTelemetry 支持服务器跟踪。从 Infinispan 15.0 开始,您需要在服务器的设置中配置跟踪。要在 Dev Services 中启用跟踪,您需要使用 `quarkus.infinispan-client.devservices.config-files`属性添加额外的设置。

Infinispan supports server tracing using OpenTelemetry. Starting from Infinispan 15.0, you need to configure tracing in the server’s settings. To enable tracing in Dev Services, you need to add extra settings using the quarkus.infinispan-client.devservices.config-files property.

infinispan:
        cacheContainer:
                tracing:
                        collector-endpoint: "http://jaeger:4318" 1
                        enabled: true 2
                        exporter-protocol: "OTLP" 3
                        service-name: "infinispan-server" 4
                        security: false 5
1 Collector endpoint. Assuming a container service name 'jaeger' is running.
2 Enables tracing.
3 Exporter protocol. OLTP is the OpenTelemetry protocol.
4 The service name that will be registered in the tracing collector, Jaeger in this case.
5 Enables 'security' category tracing.

请参阅以下 XML 和 JSON 等效文件。

See below the equivalent in XML and JSON.

<infinispan>
  <cache-container statistics="true">
    <tracing collector-endpoint="http://jaeger:4318"
             enabled="true"
             exporter-protocol="OTLP"
             service-name="infinispan-server"
             security="false" />
  </cache-container>
</infinispan>
{
  "infinispan" : {
    "cache-container" : {
      "statistics" : true,
      "tracing" : {
        "collector-endpoint" : "http://jaeger:4318",
        "enabled" : true,
        "exporter-protocol" : "OTLP",
        "service-name" : "infinispan-server",
        "security" : false
      }
    }
  }
}

您需要命名 Jaeger 服务或运行以下命令来获取运行出口端点的 IP。

You need to name the Jaeger service or get the IP running the following command to configure the exporter endpoint.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' jaeger

Persistence layer for Infinispan

Infinispan 缓存提供了一些功能,需要使用特定 SQL 数据库驱动程序连接到持久层,例如将缓存持久保存到 SQL 数据库或使用 SQL 缓存存储卸载数据库表或查询。

Infinispan caches provide several features that need to connect to a persistence layer using a particular SQL database driver such as persisting caches in a SQL database or off-loading database tables or queries with SQL cache stores.

Infinispan 需要 SQL Java 驱动程序,具体取决于应用程序使用的数据库类型。要启动带有特定 SQL 驱动程序的容器,请配置 quarkus.infinispan-client.devservices.artifacts

Infinispan needs the SQL Java Driver depending on the database kind the application is using. To spin up a container with a particular SQL driver, configure quarkus.infinispan-client.devservices.artifacts.

要了解有关持久性和 SQL 缓存存储的详细信息,请查看 SQL Store Demo + Quarkus DemoInfinispan Persistence Documentation 指南。

Learn more about persistence and SQL Cache Stores check the SQL Store Demo + Quarkus Demo and the Infinispan Persistence Documentation guide.

Shared server

大多数情况下,您需要在应用程序之间共享服务器。Infinispan 的 Dev Services 为多个在 dev 模式下运行的 Quarkus 应用程序实现了一个 service discovery 机制,以共享一个服务器。

Most of the time you need to share the server between applications. Dev Services for Infinispan implements a service discovery mechanism for your multiple Quarkus applications running in dev mode to share a single server.

Infinispan 的 Dev Services 使用 infinispan 标签启动容器,该标签用于识别容器。

Dev Services for Infinispan starts the container with the infinispan label which is used to identify the container.

如果您需要多个(共享)服务器,则可以配置 quarkus.infinispan-client.devservices.service-name 属性并指示服务器名称。它寻找具有相同值的新容器,如果没有找到则启动一个新容器。默认服务名称为 infinispan

If you need multiple (shared) servers, you can configure the quarkus.infinispan-client.devservices.service-name attribute and indicate the server name. It looks for a container with the same value, or starts a new one if none can be found. The default service name is infinispan.

在开发模式下默认启用共享,但在测试模式下禁用共享。您可以使用 quarkus.infinispan-client.devservices.shared=false 禁用共享。

Sharing is enabled by default in dev mode, but disabled in test mode. You can disable the sharing with quarkus.infinispan-client.devservices.shared=false