-
-
Save umit/454b4e8e68a5ee70724428bc8c6bb46f to your computer and use it in GitHub Desktop.
Flux Mono
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> images = IntStream.range(0, 100).mapToObj(each -> "https://picsum.photos/1024/1024/?random").collect(Collectors.toList()); | |
Scheduler subWorker = Schedulers.fromExecutor(Executors.newFixedThreadPool(20)); | |
Scheduler pubWorker = Schedulers.newParallel("aaaa", 5); | |
RestTemplate restTemplate = new RestTemplate(); | |
Function<String, Publisher<byte[]>> stringPublisherFunction = each -> Mono.defer(() -> { | |
System.out.println("flux:Mono executor: " + Thread.currentThread().getName() + "- " + Thread.currentThread().getId()); | |
return Mono.just(restTemplate.getForObject(each, byte[].class)); | |
}).subscribeOn(subWorker); | |
Flux<byte[]> flux = Flux.fromIterable(images).publishOn(pubWorker).flatMap(stringPublisherFunction); | |
flux.subscribe(new Consumer<byte[]>() { | |
@Override | |
public void accept(byte[] bytes) { | |
System.out.println("flux:subscribe executor: " + Thread.currentThread().getName() + "- " + Thread.currentThread().getId()); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment