Spring WebFlux supports the following features and archetypes:
The event loop concurrency model
Both annotated controllers and functional endpoints
Reactive clients
Netty and Servlet 3.1 container-based web servers, such as Tomcat, Undertow, and Jetty
xxxxxxxxxx
@SpringBootApplication
public class DemoClientApplication {
public static void main(String[] args) {
SpringApplication.run(DemoClientApplication.class, args);
WebClient webClient = WebClient.builder().baseUrl("http://localhost:8080/").build();
webClient.get().uri("v1/books")
.retrieve()
.bodyToFlux(Book.class)
.log()
.subscribe(new Subscriber() {
Subscription s;
@Override
public void onSubscribe(Subscription s) {
s.request(1);
this.s = s;
}
@Override
public void onNext(Object o) {
Book b = (Book) o;
System.out.println(b.getName()+" from flux");
s.request(1);
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
System.out.println("done");
}
});
webClient.get().uri("v1/books/1")
.retrieve()
.bodyToMono(Book.class)
.log()
.subscribe(new Subscriber() {
@Override
public void onSubscribe(Subscription s) {
s.request(1);
}
@Override
public void onNext(Object o) {
Book b = (Book)o;
System.out.println(b.getName());
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
});
}
}