|
13 | 13 | import com.baeldung.debugging.consumer.model.Foo; |
14 | 14 |
|
15 | 15 | import reactor.core.publisher.Flux; |
| 16 | +import reactor.core.scheduler.Schedulers; |
16 | 17 |
|
17 | 18 | @Component |
18 | 19 | public class FooService { |
@@ -88,4 +89,32 @@ public void processUsingApproachFourWithInitialCheckpoint(Flux<Foo> flux) { |
88 | 89 | flux.subscribe(); |
89 | 90 | } |
90 | 91 |
|
| 92 | + public void processUsingApproachFivePublishingToDifferentParallelThreads(Flux<Foo> flux) { |
| 93 | + logger.info("starting approach five-parallel!"); |
| 94 | + flux = concatAndSubstringFooName(flux).publishOn(Schedulers.newParallel("five-parallel-foo")) |
| 95 | + .log(); |
| 96 | + flux = concatAndSubstringFooName(flux); |
| 97 | + flux = divideFooQuantity(flux); |
| 98 | + flux = reportResult(flux, "FIVE-PARALLEL").publishOn(Schedulers.newSingle("five-parallel-bar")); |
| 99 | + flux = concatAndSubstringFooName(flux).doOnError(error -> { |
| 100 | + logger.error("Approach 5-parallel failed!", error); |
| 101 | + }); |
| 102 | + flux.subscribeOn(Schedulers.newParallel("five-parallel-starter")) |
| 103 | + .subscribe(); |
| 104 | + } |
| 105 | + |
| 106 | + public void processUsingApproachFivePublishingToDifferentSingleThreads(Flux<Foo> flux) { |
| 107 | + logger.info("starting approach five-single!"); |
| 108 | + flux = flux.log() |
| 109 | + .subscribeOn(Schedulers.newSingle("five-single-starter")); |
| 110 | + flux = concatAndSubstringFooName(flux).publishOn(Schedulers.newSingle("five-single-foo")); |
| 111 | + flux = concatAndSubstringFooName(flux); |
| 112 | + flux = divideFooQuantity(flux); |
| 113 | + flux = reportResult(flux, "FIVE-SINGLE").publishOn(Schedulers.newSingle("five-single-bar")); |
| 114 | + flux = concatAndSubstringFooName(flux).doOnError(error -> { |
| 115 | + logger.error("Approach 5-single failed!", error); |
| 116 | + }); |
| 117 | + flux.subscribe(); |
| 118 | + } |
| 119 | + |
91 | 120 | } |
0 commit comments