バックプレッシャーとオペレーター
リアクティブストリームを変換・制御します
「バックプレッシャーとオペレーター」はCoddyKit上の無料Spring Boot 4 Microservices & REST APIsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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, 3Using 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, 2Buffering 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,limitRateshape the stream
よくある質問
「バックプレッシャーとオペレーター」レッスンは無料ですか?
はい。「バックプレッシャーとオペレーター」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Spring Boot 4 Microservices & REST APIsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Spring Boot 4 Microservices & REST APIsコースには全4レッスンが含まれています。
「バックプレッシャーとオペレーター」で何を学びますか?
リアクティブストリームを変換・制御します ブラウザで直接実行するハンズオンコードでSpring Boot 4 Microservices & REST APIsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Spring Boot 4 Microservices & REST APIsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSpring Boot 4 Microservices & REST APIsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「バックプレッシャーとオペレーター」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSpring Boot 4 Microservices & REST APIsレッスンでコードを書いて実行できますか?
はい。すべてのSpring Boot 4 Microservices & REST APIsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- MonoとFluxの基礎
- リアクティブコントローラー
- リアクティブな呼び出しにWebClientを使う
- バックプレッシャーとオペレーター