0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · Lekcja

Nasłuchiwacze równoważenia i członkostwo statyczne

Dowiedzą się Państwo, jak równoważenie grup konsumentów zakłóca przetwarzanie oraz jak nasłuchiwacze równoważenia i członkostwo statyczne ograniczają przestoje i utratę stanu.

Nasłuchiwacze równoważenia i członkostwo statyczne to bezpłatna lekcja Advanced Spring Boot 4: Event-Driven Architecture (Kafka) na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Advanced Spring Boot 4: Event-Driven Architecture (Kafka), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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.

Często zadawane pytania

Czy lekcja „Nasłuchiwacze równoważenia i członkostwo statyczne” jest bezpłatna?

Tak — pełny tekst „Nasłuchiwacze równoważenia i członkostwo statyczne” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Advanced Spring Boot 4: Event-Driven Architecture (Kafka), przejdź na CoddyKit PRO. Kurs Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera 4 lekcji w sumie.

Co nauczysz się w „Nasłuchiwacze równoważenia i członkostwo statyczne”?

Dowiedzą się Państwo, jak równoważenie grup konsumentów zakłóca przetwarzanie oraz jak nasłuchiwacze równoważenia i członkostwo statyczne ograniczają przestoje i utratę stanu. Ćwiczysz Advanced Spring Boot 4: Event-Driven Architecture (Kafka) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?

Nie wymagamy żadnego doświadczenia. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Nasłuchiwacze równoważenia i członkostwo statyczne”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?

Tak. Każda lekcja Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Ręczne zatwierdzanie offsetów
  2. Wstrzymywanie i wznawianie konsumentów
  3. Współbieżność i zarządzanie wątkami
  4. Nasłuchiwacze równoważenia i członkostwo statyczne
← Powrót do Advanced Spring Boot 4: Event-Driven Architecture (Kafka)