ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่
เรียนรู้ว่าการปรับสมดุลใหม่ของกลุ่มผู้บริโภครบกวนการประมวลผลอย่างไร และตัวรับฟังการปรับสมดุลใหม่ร่วมกับสมาชิกแบบคงที่ช่วยลดเวลาหยุดทำงานและการสูญเสียสถานะได้อย่างไร
ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่ เป็นบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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-1Session 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: 3000Cooperative 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.CooperativeStickyAssignorAvoiding 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.
คำถามที่พบบ่อย
บทเรียน “ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส 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) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) นี้ได้ไหม
ได้ บทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การยืนยันออฟเซ็ตด้วยตนเอง
- การหยุดชั่วคราวและเริ่มผู้ใช้ใหม่
- การทำงานพร้อมกันและการจัดการเธรด
- ตัวรับฟังการปรับสมดุลใหม่และสมาชิกแบบคงที่