The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Dev Services para o Kafka

If any Kafka-related extension is present (e.g. quarkus-messaging-kafka), Dev Services for Kafka automatically starts a Kafka broker in dev mode and when running tests. So, you don’t have to start a broker manually. The application is configured automatically.

Because starting a Kafka broker can be long, Dev Services for Kafka uses Redpanda, a Kafka compatible broker which starts in ~1 second.

Ativar/desativar Dev Services para o Kafka

Os Dev Services para o Kafka é ativado automaticamente, a menos que:

  • quarkus.kafka.devservices.enabled esteja definido como false

  • o kafka.bootstrap.servers esteja configurado

  • todos os canais Kafka de mensagens reativas tenham o atributo bootstrap.servers definido

Dev Services for Kafka 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 kafka.bootstrap.servers.

broker compartilhado

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

O Dev Services para o Kafka inicia o broker com a etiqueta quarkus-dev-service-kafka que é utilizada para identificar o container.

If you need multiple (shared) brokers, you can configure the quarkus.kafka.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 kafka.

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

Definindo a porta

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

Note que o endereço anunciado do Kafka é automaticamente configurado com a porta escolhida.

Configurando a imagem

Dev Services for Kafka supports Redpanda, kafka-native and Strimzi (in Kraft mode) images.

Redpanda is a Kafka compatible event streaming platform. Because it provides a fast startup times, Dev Services defaults to Redpanda images from redpandadata/redpanda. You can select any version from https://hub.docker.com/r/redpandadata/redpanda.

kafka-native provides images of standard Apache Kafka distribution compiled to native binary using Quarkus and GraalVM. While still being experimental, it provides very fast startup times with small footprint.

O tipo da imagem pode ser configurado utilizando

quarkus.kafka.devservices.provider=kafka-native

Strimzi provides container images and Operators for running Apache Kafka on Kubernetes. While Strimzi is optimized for Kubernetes, the images work perfectly in classic container environments. Strimzi container images run "genuine" Kafka broker on JVM, which is slower to start.

quarkus.kafka.devservices.provider=strimzi

Para o Strimzi, você pode selecionar qualquer imagem com uma versão Kafka que tenha suporte para o Kraft (2.8.1 e superior) em https://quay.io/repository/strimzi-test-container/test-container?tab=tags

quarkus.kafka.devservices.image-name=quay.io/strimzi-test-container/test-container:0.106.0-kafka-3.7.0

Configurando os tópicos no Kafka

You can configure the Dev Services for Kafka to create topics once the broker is started. Topics are created with given number of partitions and 1 replica.

The following example creates a topic named test with 3 partitions, and a second topic named messages with 2 partitions.

quarkus.kafka.devservices.topic-partitions.test=3
quarkus.kafka.devservices.topic-partitions.messages=2

If a topic already exists with the given name, the creation is skipped, without trying to re-partition the existing topic to a different number of partitions.

Você pode configurar o tempo limite para as chamadas do client admin do Kafka utilizadas na criação de tópicos utilizando quarkus.kafka.devservices.topic-partitions-timeout. A predefinição é de 2 segundos.

Suporte aos producers transacionais e idempotentes

By default, the Redpanda broker is configured to enable transactions and idempotence features. You can disable those using:

quarkus.kafka.devservices.redpanda.transaction-enabled=false
As transações Redpanda não suportam um processamento exatamente único.

Configuration reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Tipo

Padrão

If Dev Services for Kafka has been explicitly enabled or disabled. Dev Services are generally enabled by default, unless there is an existing configuration present. For Kafka, Dev Services starts a broker unless kafka.bootstrap.servers is set or if all the Reactive Messaging Kafka channel are configured with a bootstrap.servers.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_ENABLED

Show more

boolean

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_PORT

Show more

int

Kafka dev service container type.

Redpanda, Strimzi and kafka-native container providers are supported. Default is redpanda.

Note that Strimzi and Kafka Native images are launched in Kraft mode.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_PROVIDER

Show more

redpanda, strimzi, kafka-native

redpanda

The Kafka container image to use.

Dependent on the provider.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_IMAGE_NAME

Show more

string

Indicates if the Kafka broker 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 Kafka starts a new container.

The discovery uses the quarkus-dev-service-kafka label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_SHARED

Show more

boolean

true

The value of the quarkus-dev-service-kafka 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 Kafka looks for a container with the quarkus-dev-service-kafka 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-kafka label set to the specified value.

This property is used when you need multiple shared Kafka brokers.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_SERVICE_NAME

Show more

string

kafka

The topic-partition pairs to create in the Dev Services Kafka broker. After the broker is started, given topics with partitions are created, skipping already existing topics. For example, quarkus.kafka.devservices.topic-partitions.test=2 will create a topic named test with 2 partitions.

The topic creation will not try to re-partition existing topics with different number of partitions.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_TOPIC_PARTITIONS__TOPIC_NAME_

Show more

Map<String,Integer>

Timeout for admin client calls used in topic creation.

Defaults to 2 seconds.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_TOPIC_PARTITIONS_TIMEOUT

Show more

Duration 

2S

Environment variables that are passed to the container.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_CONTAINER_ENV__ENVIRONMENT_VARIABLE_NAME_

Show more

Map<String,String>

Enables transaction support. Also enables the producer idempotence. Find more info about Redpanda transaction support on https://vectorized.io/blog/fast-transactions/. Notice that KIP-447 (producer scalability for exactly once semantic) and KIP-360 (Improve reliability of idempotent/transactional producer) are not supported.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_REDPANDA_TRANSACTION_ENABLED

Show more

boolean

true

Port to access the Redpanda HTTP Proxy (pandaproxy).

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_KAFKA_DEVSERVICES_REDPANDA_PROXY_PORT

Show more

int

About the Duration format

To write duration values, use the standard java.time.Duration format. See the Duration#parse() Java API documentation for more information.

Você também pode usar um formato simplificado, começando com um número:

  • Se o valor for apenas um número, ele representará o tempo em segundos.

  • Se o valor for um número seguido de 'ms', ele representa o tempo em milissegundos.

Em outros casos, o formato simplificado é traduzido para o formato 'java.time.Duration' para análise:

  • Se o valor for um número seguido de 'h', 'm' ou 's', ele é prefixado com 'PT'.

  • Se o valor for um número seguido de 'd', ele é prefixado com 'P'.

Conteúdo Relacionado