Dev Services for Kafka
Kafka関連のエクステンション(例: quarkus-messaging-kafka )がある場合、Dev Services for Kafkaは開発モードやテスト実行時に自動的にKafkaブローカーを起動します。
そのため、手動でブローカーを起動する必要はありません。
アプリケーションは自動的に設定されます。
| By default, Dev Services for Kafka uses the Apache Kafka native image which starts in ~1 second. |
Dev Services for Kafkaの有効化/無効化
以下の場合を除き、Dev Services for Kafkaが自動的に有効になります:
-
quarkus.kafka.devservices.enabledがfalseに設定されている場合 -
kafka.bootstrap.serversが設定されている場合 -
すべてのReactive Messaging Kafkaチャンネルに
bootstrap.servers属性が設定されている場合
Dev Services for Kafkaでは、ブローカーの起動にDockerを使用しています。お使いの環境でDockerがサポートされていない場合は、ブローカーを手動で起動するか、すでに稼働しているブローカーに接続する必要があります。ブローカーのアドレスは、 kafka.bootstrap.servers を使用して設定できます。
共有ブローカー
ほとんどの場合、アプリケーション間でブローカーを共有する必要があります。Dev Services for Kafkaは、 開発 モードで動作する複数のQuarkusアプリケーションが1つのブローカーを共有するための サービス発見 メカニズムを実装しています。
Dev Services for Kafka は、コンテナを識別するために使用される quarkus-dev-service-kafka のラベルでコンテナを開始します。
|
複数の(共有)ブローカーが必要な場合は、 quarkus.kafka.devservices.service-name 属性を設定し、ブローカー名を示します。同じ値のコンテナを探し、見つからない場合は新しいコンテナを開始します。デフォルトのサービス名は kafka です。
共有は、devモードではデフォルトで有効ですが、testモードでは無効です。 quarkus.kafka.devservices.shared=false で共有を無効に設定可能です。
ポートの設定
デフォルトでは、Kafka向けDev Services はランダムなポートを選択してアプリケーションを構成します。ポートは、 quarkus.kafka.devservices.port プロパティを構成することで設定できます。
Kafkaのアドバタイズされたアドレスは、選択したポートで自動的に設定されることに注意してください。
イメージの設定
Dev Services for Kafka supports the following container providers:
upstream-kafka-native (default) uses the official Apache Kafka native image, compiled with GraalVM for fast startup.
upstream-kafka uses the official Apache Kafka JVM image.
quarkus.kafka.devservices.provider=upstream-kafka
Redpanda is a Kafka compatible event streaming platform. You can select any version from https://hub.docker.com/r/redpandadata/redpanda.
quarkus.kafka.devservices.provider=redpanda
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 a Kafka broker on JVM, which is slower to start.
quarkus.kafka.devservices.provider=strimzi
Strimzi では、Kafka のバージョンが Kraft に対応しているもの(2.8.1 以上)であれば、 https://quay.io/repository/strimzi-test-container/test-container?tab=tags から任意のイメージを選択することができます。
quarkus.kafka.devservices.image-name=quay.io/strimzi-test-container/test-container:0.115.0-kafka-4.2.0
Kafkaトピックの設定
Kafka向けDev Services を設定して、ブローカーの起動時にトピックを作成できます。トピックは、指定されたパーティション数と1つのレプリカで作成されます。構文は以下のとおりです。
quarkus.kafka.devservices.topic-partitions.<topic-name>=<number-of-partitions>
次の例では、3つのパーティションを持つ test という名前のトピックと、2つのパーティションを持つ messages という名前の2番目のトピックを作成します。
quarkus.kafka.devservices.topic-partitions.test=3
quarkus.kafka.devservices.topic-partitions.messages=2
指定された名前のトピックがすでに存在する場合、既存のトピックを異なる数のパーティションに再分割しようとはせず、作成はスキップされます。
quarkus.kafka.devservices.topic-partitions-timeout を使用して、トピック作成時に使用される Kafka admin クライアントコールのタイムアウトを設定できます。デフォルトは 2 秒です。
トランザクションとべき等プロデューサーのサポート
デフォルトではRedpanda ブローカーはトランザクションと冪等機能を有効化するように設定されています。 以下の設定でそれらを無効にすることができます:
quarkus.kafka.devservices.redpanda.transaction-enabled=false
| Redpandaのトランザクションは正確に一回(exactly once)の処理をサポートしません。 |
Compose
Kafka Dev Services は Compose Dev Services をサポートしています。これは、以下のような compose-devservices.yml に依存します。
name: <application name>
services:
kafka:
image: apache/kafka-native:4.2.0
restart: "no"
ports:
- '9092'
labels:
io.quarkus.devservices.compose.exposed_ports: /etc/kafka/docker/ports
environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_NUM_PARTITIONS: 3
command: "/kafka.sh"
volumes:
- './kafka.sh:/kafka.sh'
ブローカーがその外部からアクセス可能なアドレスをクライアントにアドバタイズするには、実行中のコンテナーへのポートマッピングの公開 に記述されているように、追加のファイル kafka.sh が必要です。
設定リファレンス
ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。
Configuration property |
タイプ |
デフォルト |
|---|---|---|
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 Environment variable: Show more |
ブーリアン |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: Show more |
int |
|
Kafka dev service container type. Redpanda, Strimzi, kafka-native and upstream kafka container providers are supported. Default is upstream-kafka-native. For Redpanda: See https://docs.redpanda.com/current/get-started/quick-start/ and https://hub.docker.com/r/redpandadata/redpanda For Strimzi: See https://github.com/strimzi/test-container and https://quay.io/repository/strimzi-test-container/test-container For Kafka Native: See https://github.com/ozangunalp/kafka-native and https://quay.io/repository/ogunalp/kafka-native For Upstream Kafka: See https://hub.docker.com/r/apache/kafka and https://hub.docker.com/r/apache/kafka-native Environment variable: Show more |
|
|
The Kafka container image to use. Dependent on the provider. Environment variable: 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 Container sharing is only used in dev mode. Environment variable: Show more |
ブーリアン |
|
The value of the This property is used when you need multiple shared Kafka brokers. Environment variable: Show more |
string |
|
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, The topic creation will not try to re-partition existing topics with different number of partitions. Environment variable: Show more |
Map<String,Integer> |
|
Timeout for admin client calls used in topic creation. Defaults to 2 seconds. Environment variable: Show more |
|
|
Environment variables that are passed to the container. Environment variable: 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: Show more |
ブーリアン |
|
Port to access the Redpanda HTTP Proxy (pandaproxy). If not defined, the port will be chosen randomly. Environment variable: Show more |
int |
|
Configuration properties that will be added to the server properties file provided to the Kafka broker by the Strimzi provider. Environment variable: Show more |
Map<String,String> |
|
期間フォーマットについて
期間の値を書くには、標準の 数字で始まる簡略化した書式を使うこともできます:
その他の場合は、簡略化されたフォーマットが解析のために
|