sábado, 7 de diciembre de 2019

Simple Spring Reactive 2018 Mono, Flux

Simple Spring Reactive 2018 demo Mono, Flux




Using Mono

package com.bext;
import org.springframework.boot.CommandLineRunner; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; 
import reactor.core.publisher.Mono; 
 
 @SpringBootApplicationpublic class SpringReactive2018Application {

   public static void main(String[] args) {
      SpringApplication.run(SpringReactive2018Application.class, args);    
   }

   @Bean   CommandLineRunner demo() {
      return args -> {
         Mono<String> miMono = Mono.just("Mono maneja un solo dato"); 
         miMono.subscribe(System.out::println);      }; 
     }
}

Run

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2019-12-07 18:58:46.769  INFO 20348 --- [           main] com.bext.SpringReactive2018Application   : Starting SpringReactive2018Application on DESKTOP-NLF0058 with PID 20348 (D:\Descargas\SpringReactive2018\target\classes started by bext in D:\Descargas\SpringReactive2018)
2019-12-07 18:58:46.770  INFO 20348 --- [           main] com.bext.SpringReactive2018Application   : No active profile set, falling back to default profiles: default
2019-12-07 18:58:47.780  INFO 20348 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
2019-12-07 18:58:47.783  INFO 20348 --- [           main] com.bext.SpringReactive2018Application   : Started SpringReactive2018Application in 1.208 seconds (JVM running for 1.808)
Mono maneja un solo dato


Using Flux

package com.bext;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; 
import reactor.core.publisher.Flux; 
 
@SpringBootApplication 
public class SpringReactive2018Application {

   public static void main(String[] args) {
      SpringApplication.run(SpringReactive2018Application.class, args);    
   }

   @Bean   CommandLineRunner demo() {
      return args -> {
         Flux<String> miFlux = Flux.fromArray("1,2,3,4,5,6".split(",")); 
         miFlux.map(Integer::parseInt)
                    .filter(i -> i % 2 == 0)
                    .subscribe(System.out::println, null, null); 
      }; 
   }
}

Run

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.2.RELEASE)

2019-12-07 19:22:39.436  INFO 27864 --- [           main] com.bext.SpringReactive2018Application   : Starting SpringReactive2018Application on DESKTOP-NLF0058 with PID 27864 (D:\Descargas\SpringReactive2018\target\classes started by bext in D:\Descargas\SpringReactive2018)
2019-12-07 19:22:39.438  INFO 27864 --- [           main] com.bext.SpringReactive2018Application   : No active profile set, falling back to default profiles: default
2019-12-07 19:22:40.455  INFO 27864 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
2019-12-07 19:22:40.458  INFO 27864 --- [           main] com.bext.SpringReactive2018Application   : Started SpringReactive2018Application in 1.206 seconds (JVM running for 1.821)
2
4
6



eot

No hay comentarios:

Publicar un comentario