Dev Services for RabbitMQ

用于 RabbitMQ 的 Dev Services 会在开发者模式下和运行测试时自动启动一个 RabbitMQ 代理。因此,您不必手动启动代理。应用程序会自动配置。

Dev Services for RabbitMQ automatically starts a RabbitMQ broker in dev mode and when running tests. So, you don’t have to start a broker manually. The application is configured automatically.

Enabling / Disabling Dev Services for RabbitMQ

除非满足以下条件,否则用于 RabbitMQ 的 Dev Services 会自动启用:

Dev Services for RabbitMQ is automatically enabled unless:

  • quarkus.rabbitmq.devservices.enabled is set to false

  • the rabbitmq-host or rabbitmq-port is configured

  • all the Reactive Messaging RabbitMQ channels have the host or port attributes set

用于 RabbitMQ 的 Dev Services 依靠 Docker 启动代理。如果您的环境不支持 Docker,您需要手动启动代理,或连接到一个已在运行的代理。您可以使用 rabbitmq-hostrabbitmq-port、`rabbitmq-username`和 `rabbitmq-password`属性配置代理访问。

Dev Services for RabbitMQ 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 access using the rabbitmq-host, rabbitmq-port, rabbitmq-username and rabbitmq-password properties.

Shared broker

大多数时候,您需要在应用程序之间共享代理。用于 RabbitMQ 的 Dev Services 为运行在 _dev_模式下的多个 Quarkus 应用程序实施了一个 _service discovery_机制,用于共享一个代理。

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

用于 RabbitMQ 的 Dev Services 使用 `quarkus-dev-service-rabbitmq`标记启动容器,该标记用于识别容器。

Dev Services for RabbitMQ starts the container with the quarkus-dev-service-rabbitmq label which is used to identify the container.

如果您需要多个(共享)代理,您可以配置 quarkus.rabbitmq.devservices.service-name`属性并指定代理名称。它会查找一个具有相同值的容器,或在找不到时启动一个新容器。默认服务名称为 `rabbitmq

If you need multiple (shared) brokers, you can configure the quarkus.rabbitmq.devservices.service-name attribute and indicate the broker 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 rabbitmq.

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

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

Setting the port

默认情况下,用于 RabbitMQ 的 Dev Services 会选择一个随机端口并配置应用程序。您可以通过配置 `quarkus.rabbitmq.devservices.port`属性设置端口。

By default, Dev Services for RabbitMQ picks a random port and configures the application. You can set the port by configuring the quarkus.rabbitmq.devservices.port property.

Configuring the image

RabbitMQ 的 Dev Services 使用 [role="bare"][role="bare"]https://hub.docker.com/_/rabbitmq提供的官方镜像。您可以使用 `quarkus.rabbitmq.devservices.image-name`属性配置镜像和版本:

Dev Services for RabbitMQ uses official images available at [role="bare"]https://hub.docker.com/_/rabbitmq. You can configure the image and version using the quarkus.rabbitmq.devservices.image-name property:

quarkus.rabbitmq.devservices.image-name=rabbitmq:latest

Access the management UI

默认情况下,RabbitMQ 的 Dev Services 使用带有 `management`标记的官方镜像。这意味着您可以使用 management plugin 它。您可以使用 Dev UI来随机影响 HTTP 端口或通过 `quarkus.rabbitmq.devservices.http-port`配置一个静态端口。

By default, Dev Services for RabbitMQ use the official image with the management tag. This means you have the management plugin available. You can use the Dev UI to find the HTTP port randomly affected or configure a static one via quarkus.rabbitmq.devservices.http-port.

Predefined Topology

RabbitMQ 的 Dev Services 支持在代理启动时定义拓扑。您可以使用标准 Quarkus 配置定义交易所、队列和绑定。

Dev Services for RabbitMQ supports defining topology upon broker start. You can define Exchanges, Queues, and Bindings using standard Quarkus configuration.

Defining Exchanges

要定义 RabbitMQ 交易所,您在 `quarkus.rabbitmq.devservices.exchanges`键后面提供交易所名称,后面紧跟一个(或更多)交易所的属性:

To define a RabbitMQ exchange you provide the exchange’s name after the quarkus.rabbitmq.devservices.exchanges key, followed by one (or more) of the exchange’s properties:

quarkus.rabbitmq.devservices.exchanges.my-exchange.type=topic            # defaults to 'direct'
quarkus.rabbitmq.devservices.exchanges.my-exchange.auto-delete=false     # defaults to 'false'
quarkus.rabbitmq.devservices.exchanges.my-exchange.durable=true          # defaults to 'false'

此外,还可以使用 `arguments`键将任何其他参数提供给交易所的定义:

Additionally, any additional arguments may be provided to the exchange’s definition by using the arguments key:

quarkus.rabbitmq.devservices.exchanges.my-exchange.arguments.alternate-exchange=another-exchange

Defining Queues

要定义 RabbitMQ 队列,您在 `quarkus.rabbitmq.devservices.queues`键后面提供队列名称,后面紧跟一个(或更多)队列的属性:

To define a RabbitMQ queue you provide the queue’s name after the quarkus.rabbitmq.devservices.queues key, followed by one (or more) of the queue’s properties:

quarkus.rabbitmq.devservices.queues.my-queue.auto-delete=false          # defaults to 'false'
quarkus.rabbitmq.devservices.queues.my-queue.durable=true               # defaults to 'false'

此外,还可以使用 `arguments`键将任何其他参数提供给队列的定义:

Additionally, any additional arguments may be provided to the queue’s definition by using the arguments key:

quarkus.rabbitmq.devservices.queues.my-queue.arguments.x-dead-letter-exchange=another-exchange

Defining Bindings

要定义 RabbitMQ 绑定,您在 `quarkus.rabbitmq.devservices.bindings`键后面提供绑定的名称,后面紧跟一个(或更多)绑定的属性:

To define a RabbitMQ binding you provide the binding’s name after the quarkus.rabbitmq.devservices.bindings key, followed by one (or more) of the binding’s properties:

quarkus.rabbitmq.devservices.bindings.a-binding.source=my-exchange      # defaults to name of binding
quarkus.rabbitmq.devservices.bindings.a-binding.routing-key=some-key    # defaults to '#'
quarkus.rabbitmq.devservices.bindings.a-binding.destination=my-queue    # defaults to name of binding
quarkus.rabbitmq.devservices.bindings.a-binding.destination-type=queue  # defaults to 'queue'

绑定的名称仅用于 Dev Services 配置的目的,而不是 RabbitMQ 中定义的绑定的一部分。

The name of the binding is only used for the purposes of the Dev Services configuration and is not part of the binding defined in RabbitMQ.

此外,还可以使用 `arguments`键将任何其他参数提供给绑定的定义:

Additionally, any additional arguments may be provided to the binding’s definition by using the arguments key:

quarkus.rabbitmq.devservices.bindings.a-binding.arguments.non-std-option=value