0Pricing
Spring Boot 4 Microservices & REST APIs · บทเรียน

แรงดันย้อนกลับและตัวดำเนินการ

แปลงและควบคุมสตรีมแบบรีแอกทีฟ

แรงดันย้อนกลับและตัวดำเนินการ เป็นบทเรียน Spring Boot 4 Microservices & REST APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Microservices & REST APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Operators Build Pipelines

Reactive operators chain together to form a processing pipeline. Each operator returns a new publisher describing the next step.

Common ones: map, flatMap, filter, take, buffer.

map vs flatMap

map transforms each item synchronously (1-to-1). flatMap transforms each item into another publisher and flattens the results — use it for async work.

Using map

map for pure, synchronous transformations.

Flux<Integer> lengths = Flux.just("a", "bb", "ccc")
    .map(String::length);
lengths.subscribe(System.out::println); // 1, 2, 3

Using flatMap

flatMap when each item triggers an async call returning a Mono or Flux.

Flux<User> users = Flux.just("1", "2", "3")
    .flatMap(id -> userService.findById(id));
users.subscribe(System.out::println);

flatMap Ordering

flatMap interleaves results as inner publishers complete, so order is not guaranteed. Use concatMap to preserve order.

Flux<User> ordered = Flux.just("1", "2", "3")
    .concatMap(id -> userService.findById(id));

What is Backpressure

Backpressure is the mechanism by which a slow consumer tells a fast producer to slow down.

Subscribers request a number of items; the producer only emits up to that demand. This prevents memory overflow.

Limiting with take

take requests only the first N items, then cancels the upstream.

Flux<Long> first3 = Flux.interval(Duration.ofMillis(100))
    .take(3);
first3.subscribe(System.out::println); // 0, 1, 2

Buffering Items

buffer groups items into lists, useful for batching.

Flux<List<Integer>> batches = Flux.range(1, 10)
    .buffer(3);
batches.subscribe(System.out::println);
// [1,2,3], [4,5,6], [7,8,9], [10]

onBackpressureBuffer

When a producer is faster than the consumer, strategies control overflow: buffer, drop, or latest.

Flux.interval(Duration.ofMillis(1))
    .onBackpressureBuffer(100)
    .subscribe(System.out::println);

Throttling with limitRate

limitRate caps how many items are requested upstream at a time, applying controlled backpressure.

Flux.range(1, 1000)
    .limitRate(10)
    .subscribe(System.out::println);

Combining Operators

Real pipelines chain several operators to filter, transform, and limit a stream.

Flux.range(1, 100)
    .filter(n -> n % 2 == 0)
    .map(n -> n * n)
    .take(5)
    .subscribe(System.out::println);

Quick Check

Test your understanding of operators and backpressure.

Recap

You learned about operators and backpressure:

  • map = sync transform; flatMap = async, unordered; concatMap = async, ordered
  • Backpressure lets slow consumers control fast producers
  • take, buffer, limitRate shape the stream

คำถามที่พบบ่อย

บทเรียน “แรงดันย้อนกลับและตัวดำเนินการ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “แรงดันย้อนกลับและตัวดำเนินการ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Microservices & REST APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “แรงดันย้อนกลับและตัวดำเนินการ”

แปลงและควบคุมสตรีมแบบรีแอกทีฟ คุณปฏิบัติ Spring Boot 4 Microservices & REST APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Microservices & REST APIs หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Microservices & REST APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “แรงดันย้อนกลับและตัวดำเนินการ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Microservices & REST APIs นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Microservices & REST APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. พื้นฐาน Mono และ Flux
  2. คอนโทรลเลอร์แบบรีแอกทีฟ
  3. WebClient สำหรับการเรียกแบบรีแอกทีฟ
  4. แรงดันย้อนกลับและตัวดำเนินการ
← กลับไปที่ Spring Boot 4 Microservices & REST APIs