0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · レッスン

リバランスリスナーと静的メンバーシップ

コンシューマーグループのリバランスが処理を妨げる仕組みと、リバランスリスナーおよび静的メンバーシップで停止時間と状態の損失を最小化する方法を学びます。

「リバランスリスナーと静的メンバーシップ」はCoddyKit上の無料Advanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

What Triggers a Rebalance

A rebalance reassigns partitions among consumers in a group. It happens when a consumer joins, leaves, crashes, or its session times out.

During a rebalance, processing pauses across the group.

The Cost of Rebalancing

Frequent rebalances hurt throughput: partitions are revoked and reassigned, in-flight work may be reprocessed, and local caches are invalidated.

Advanced consumers actively minimize and react to rebalances.

Rebalance Listener Hooks

A ConsumerRebalanceListener gives you two callbacks:

  • onPartitionsRevoked — called before partitions are taken away.
  • onPartitionsAssigned — called after new partitions are granted.

Committing on Revoke

Use onPartitionsRevoked to commit offsets for work completed so far, avoiding duplicate processing after reassignment.

public void onPartitionsRevoked(Collection<TopicPartition> parts) {
    consumer.commitSync(currentOffsets);
}

Wiring It in Spring

In Spring Kafka, implement ConsumerAwareRebalanceListener and set it on the container properties.

factory.getContainerProperties()
    .setConsumerRebalanceListener(myRebalanceListener);

Static Membership

Static membership assigns each consumer a stable group.instance.id. On a brief restart, the broker keeps its partitions instead of triggering a rebalance.

spring:
  kafka:
    consumer:
      properties:
        group.instance.id: consumer-pod-1

Session and Heartbeat Timeouts

Static membership relies on session.timeout.ms. If a consumer rejoins within the session window using the same instance id, no rebalance occurs.

session.timeout.ms: 45000
heartbeat.interval.ms: 3000

Cooperative Rebalancing

The CooperativeStickyAssignor reassigns only the partitions that must move, instead of revoking everything (stop-the-world). This dramatically reduces rebalance impact.

partition.assignment.strategy: org.apache.kafka.clients.consumer.CooperativeStickyAssignor

Avoiding Poll Timeouts

If processing a batch exceeds max.poll.interval.ms, the broker assumes the consumer is dead and rebalances. Keep per-poll work bounded or raise the interval.

Combining Strategies

For resilient consumers, combine static membership (avoid restart churn), cooperative rebalancing (smaller moves), and a rebalance listener (clean offset commits).

Putting It Together

Rebalances are unavoidable but controllable. Listeners let you commit cleanly, static membership avoids needless rebalances on restart, and cooperative assignment limits disruption.

Quick Check

Test your understanding of rebalancing.

Recap

You learned advanced rebalance handling.

  • Rebalances pause processing and can reprocess work.
  • Rebalance listeners let you commit offsets on revoke.
  • Static membership avoids rebalances on brief restarts.
  • Cooperative assignment reduces stop-the-world disruption.

よくある質問

「リバランスリスナーと静的メンバーシップ」レッスンは無料ですか?

はい。「リバランスリスナーと静的メンバーシップ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。

「リバランスリスナーと静的メンバーシップ」で何を学びますか?

コンシューマーグループのリバランスが処理を妨げる仕組みと、リバランスリスナーおよび静的メンバーシップで停止時間と状態の損失を最小化する方法を学びます。 ブラウザで直接実行するハンズオンコードでAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Advanced Spring Boot 4: Event-Driven Architecture (Kafka)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「リバランスリスナーと静的メンバーシップ」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンでコードを書いて実行できますか?

はい。すべてのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. オフセットの手動コミット
  2. コンシューマーの一時停止と再開
  3. 並行処理とスレッド管理
  4. リバランスリスナーと静的メンバーシップ
← Advanced Spring Boot 4: Event-Driven Architecture (Kafka)に戻る