SlideShare a Scribd company logo
loiane.com
@loiane
Full-Stack	Reativa	com	
Spring	WebFlux	+	
Angular
Agenda
•Pq	rea(vo?	
•Rea(vo	x	MVC	
•Back-end	rea(vo	com	Spring	WebFlux	
•Front-end	rea(vo	com	with	Angular	
•Gerenciamento	de	estado	com	NgRx	e	RxJS	
•Demo
@loiane
Loiane Groner
@loiane
github.com/loiane
loiane.com
loiane.training
Analista Negócios | Engenheira @ Citibank US
Tech Stack
@loiane
Arquitetura Full-Stack
Data source
Event
Source Observable<T[]>
Component ->
async pipe
ngRx
Redux
Repository
Flux<T>
Controller |
Routes
Flux<T>
MongoDB Spring WebFlux Angular Reativo
@loiane
@loiane
@loiane
@loiane
Programação Reativa
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams
Streams Streams Streams Streams Streams Streams Streams Streams Streams @loiane
@loiane
Aplicações Reativas
Publisher SubscriberStream
@loiane
Spring 5
https://docs.spring.io/spring-framework/docs/5.0.0.M1/spring-framework-reference/html/web-reactive.html @loiane
Spring Data
public interface ReactiveMongoRepository<T, ID> {
<S extends T> Mono<S> insert(S var1);
<S extends T> Flux<S> insert(Iterable<S> var1);
<S extends T> Flux<S> insert(Publisher<S> var1);
<S extends T> Flux<S> findAll(Example<S> var1);
<S extends T> Flux<S> findAll(Example<S> var1, Sort var2);
}
@loiane
Um Objeto
@loiane
Vários Objetos
@loiane
@loiane
Oracle Cloud
@loiane
Model
@NoArgsConstructor
@AllArgsConstructor
@Data
@Document(collection = "products")
public class Product {
@Id
private String id;
private String name;
private String description;
private Double price;
private String image;
private String status;
private String discounted;
private Double discount;
}
@loiane
Repository
public interface ProductRepository
extends ReactiveMongoRepository<Product, String> {
}
@loiane
Controller
@RestController
@RequestMapping("/api/products")
public class ProductController {
private ProductRepository repository;
public ProductController(ProductRepository repository) {
this.repository = repository;
}
}
@loiane
Controller
@GetMapping
public Flux<Product> getAll() {
return repository.findAll();
}
@GetMapping("{id}")
public Mono<ResponseEntity<Product!>> getById(@PathVariable String id) {
return repository.findById(id)
.map(product !-> ResponseEntity.ok(product))
.defaultIfEmpty(ResponseEntity.notFound().build());
}
@loiane
Controller: WebFlux x MVC
@GetMapping
public Flux<Product> getAll() {
return repository.findAll();
}
@GetMapping
public List findAll(){
return repository.findAll();
}
WebFlux
MVC
@loiane
Controller: WebFlux x MVC
@GetMapping(“{id}")
public Mono<ResponseEntity<Product!>> getById(@PathVariable String id) {
return repository.findById(id)
.map(product !-> ResponseEntity.ok(product))
.defaultIfEmpty(ResponseEntity.notFound().build());
}
@GetMapping(path = {"{id}"})
public ResponseEntity<Contact> findById(@PathVariable("id") long id){
return repository.findById(id)
.map(record !-> ResponseEntity.ok().body(record))
.orElse(ResponseEntity.notFound().build());
}
WebFlux
MVC
@loiane
Mundo Real
List<Order> getOrders(int customerId)
List<Product> getProducts(Order order)
ShippingStatus getShippingStatus(Order o, Product p)
getOrdersAsync(1) !// Flux<Order>
    .flatMap(o !-> getProductsAsync(o) !// Flux<Product>
            .flatMap(p !-> getShippingStatusAsync(o, p))
    );
@loiane
Backpressure
@loiane
Streams
Source: https://jakearchibald.com/2016/streams-ftw/ @loiane
Streams
NJSON
Newline delimited JSON @loiane
Backpressure
@GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Order> streamOrderStatus() {
return repository.findAll().delayElements(Duration.ofSeconds(7));
}
@loiane
Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl
Angular Reativo
•HKp	
•Router	
•Guards	
•Forms
@loiane
Observable
Observable ObserverOperadores
Data Source
Fonte
Transforma os dados
Consumer
Consumidor
Observable emite valores assíncronos e notifica observers
@loiane
Angular Http + Spring
load() {
return this.http.get<Contact[]>(this.API)
.pipe(
take(1),
tap(data !=> this.contactsCache = data)
);
}
create(record: Contact) {
return this.http.post<Contact>(this.API, record).pipe(take(1));
}
update(record: Contact) {
return this.http.put<Contact>(`${this.API}/${record.id}`, record).pipe(take(1));
}
remove(id: number) {
return this.http.delete<Contact>(`${this.API}/${id}`).pipe(take(1));
}
@loiane
Backpressure with RxJS
observeMessages(url: string): Observable<any> {
return new Observable<any>(obs !=> {
const es = new EventSource(url);
es.addEventListener('message', (evt: any) !=> {
console.log(evt.data);
obs.next(evt.data !!= null ? JSON.parse(evt.data) : evt.data);
});
return () !=> es.close();
});
}
@loiane
https://github.com/ngrx
@loiane
Fluxo de Dados Assíncrono
Reducer
dispatch
Store
subscribe
Requisita
Ação
Action
Executa o Reducer
Estado
Atualiza a View
Retorna um novo Estado
Component
@loiane
Componente inicia a mudança
@loiane
estado
Com Redux
@loiane
Store
Redux Store
Action
dispatch
subscribe
@loiane
@loiane
Apenas MongoDB?
@loiane
Desafios
@loiane
hKps://github.com/loiane/
reac(ve-spring-angular
@loiane
Referências
• hKps://docs.spring.io/spring/docs/current/spring-framework-reference/pdf/web-
reac(ve.pdf	
• hKps://docs.spring.io/spring/docs/current/spring-framework-reference/web-
reac(ve.html	
• hKp://www.reac(ve-streams.org/	
• hKps://github.com/ngrx/plaPorm	
• hKps://blog.nrwl.io/ngrx-paKerns-and-techniques-f46126e2b1e5
@loiane
Obrigada!
@loiane	
github.com/loiane	
loiane.com	
youtube.com/loianegroner

More Related Content

PDF
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
PDF
Serverless Angular, Material, Firebase and Google Cloud applications
PDF
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
PDF
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
PDF
FullStack Reativo com Spring WebFlux + Angular
PDF
Angular for Java Enterprise Developers: Oracle Code One 2018
PDF
Gerenciamento de estado no Angular com NgRx
PDF
Presente e Futuro: Java EE.next()
Full-Stack Reactive with Spring WebFlux + Angular - JConf Colombia 2019
Serverless Angular, Material, Firebase and Google Cloud applications
Full-Stack Reactive with Spring WebFlux + Angular - Oracle Code One 2018
Full-Stack Reativo com Spring WebFlux + Angular - FiqueEmCasaConf
FullStack Reativo com Spring WebFlux + Angular
Angular for Java Enterprise Developers: Oracle Code One 2018
Gerenciamento de estado no Angular com NgRx
Presente e Futuro: Java EE.next()

What's hot (20)

PDF
JavaOne 2013: Java 8 - The Good Parts
PDF
Apollo. The client we deserve
PDF
React table tutorial use filter (part 2)
PPTX
Reactive Programming in Java 8 with Rx-Java
PDF
Angular 2 observables
PDF
Introducing spring
PDF
Functional UIs with Java 8 and Vaadin JavaOne2014
PDF
Redux Universal
PPTX
React + Redux + TypeScript === ♥
PDF
Angular & RXJS: examples and use cases
PDF
Reactive Thinking in Java
PPTX
Azure Durable Functions
PDF
Using redux
PDF
Reactive Streams and RxJava2
PDF
OASGraph LoopBack 4 Integration
PDF
Reactive Thinking in Java with RxJava2
PPTX
Top 10 RxJs Operators in Angular
PDF
React state management with Redux and MobX
PDF
Angular2 Development for Java developers
PDF
Reactive programming in Angular 2
JavaOne 2013: Java 8 - The Good Parts
Apollo. The client we deserve
React table tutorial use filter (part 2)
Reactive Programming in Java 8 with Rx-Java
Angular 2 observables
Introducing spring
Functional UIs with Java 8 and Vaadin JavaOne2014
Redux Universal
React + Redux + TypeScript === ♥
Angular & RXJS: examples and use cases
Reactive Thinking in Java
Azure Durable Functions
Using redux
Reactive Streams and RxJava2
OASGraph LoopBack 4 Integration
Reactive Thinking in Java with RxJava2
Top 10 RxJs Operators in Angular
React state management with Redux and MobX
Angular2 Development for Java developers
Reactive programming in Angular 2
Ad

Similar to Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl (20)

PDF
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
PDF
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
PDF
Full Stack Reactive with React and Spring WebFlux - PWX 2019
PDF
Full Stack Reactive with React and Spring WebFlux Workshop - KCDC 2019
PDF
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
PDF
NCUG 2019: Super charge your API’s with Reactive streams
PPTX
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
PPTX
Reactive Spring 5
PDF
Social connections14: Super charge your API’s with Reactive streams
PDF
Guide to Spring Reactive Programming using WebFlux
PPTX
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
PDF
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
PDF
Building RESTFUL APIs with Spring Webflux
PDF
Refactor to Reactive With Spring 5 and Project Reactor
PDF
Reactive for the rest of us
PDF
Introduction to Spring webflux
PDF
Reactive programming with spring web flux
PPTX
Restful webservices
PPTX
Spring reactor
PDF
May 2010 - RestEasy
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - PWX 2019
Full Stack Reactive with React and Spring WebFlux Workshop - KCDC 2019
Full Stack Reactive with React and Spring WebFlux - SpringOne 2018
NCUG 2019: Super charge your API’s with Reactive streams
Stéphane Nicoll and Madhura Bhave at SpringOne Platform 2017
Reactive Spring 5
Social connections14: Super charge your API’s with Reactive streams
Guide to Spring Reactive Programming using WebFlux
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
Building RESTFUL APIs with Spring Webflux
Refactor to Reactive With Spring 5 and Project Reactor
Reactive for the rest of us
Introduction to Spring webflux
Reactive programming with spring web flux
Restful webservices
Spring reactor
May 2010 - RestEasy
Ad

Recently uploaded (20)

PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
KodekX | Application Modernization Development
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Review of recent advances in non-invasive hemoglobin estimation
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Spectral efficient network and resource selection model in 5G networks
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KodekX | Application Modernization Development
madgavkar20181017ppt McKinsey Presentation.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Review of recent advances in non-invasive hemoglobin estimation

Full-Stack Reativo com Spring WebFlux + Angular - Devs Java Girl