javaone 2016 - reactive microservices with java and java ee
TRANSCRIPT
![Page 1: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/1.jpg)
Reactive Microservices with Java and Java EERodrigo Cândido da Silva @rcandidosilva Israel Boza Rodriguez @IsraKaos
![Page 2: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/2.jpg)
Agenda• Monolithic vs. Microservices • Reactive Manifesto • Resilience • Message-driven • Demo • Q&A
![Page 3: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/3.jpg)
Monolithic vs. Microservices
![Page 4: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/4.jpg)
Microservices
• Small components • Isolated deployment • Independent technology • Separate infrastructure
"Small independent component with well-defined boundaries that’s doing one thing, but
doing it well"
![Page 5: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/5.jpg)
Reactive Manifesto
![Page 6: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/6.jpg)
Resilient• How to support it on microservices?
• Central point of configuration • Service registry and discovery • Routing features • Load balancing • Failover • Monitoring
![Page 7: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/7.jpg)
Spring BootSpring Cloud
Spring Cloud + Netflix OSS
![Page 8: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/8.jpg)
Spring Cloud + Netflix OSS“Nice match to build resilient microservices with
Java"
Configuration Management Spring Cloud Config + Bus
Service Registration and Discovery Netflix Eureka
Load Balacing Netflix Ribbon
Circuit Breaker Netflix Hystrix + Turbine
Proxy Server Netflix Zuul
Autenthication Spring Cloud Security
![Page 9: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/9.jpg)
Spring Cloud Config
![Page 10: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/10.jpg)
Netflix Eureka
![Page 11: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/11.jpg)
Netflix Ribbon
![Page 12: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/12.jpg)
Netflix Hystrix• Circuit Breaker Pattern
![Page 13: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/13.jpg)
Hystrix Dashboard
![Page 14: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/14.jpg)
Netflix Zuul
![Page 15: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/15.jpg)
Spring Cloud Security
Discovery
Client Relying Party
Resource Server
Get an access token
& an ID Token (JWT)
Use an access token
Authorization Server
Iden.tyProviderorIDPor
OpenIDProviderorOP
Authorization Endpoint
Token Endpoint
Important Stuff
Userinfo Endpoint
Registration Endpoint
JWKS Endpoint
JWKS Endpoint
Validate (JWT)
ID Token
/.well-known /webfinger /openid-configura.on
Check Session IFrame
End Session Endpoint
![Page 16: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/16.jpg)
Message-Driven • How to support it on microservices?
• Asynchronous communication • Non blocking I/O • Distributed • Consistency • Event sourcing • CQRS
![Page 17: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/17.jpg)
Reactive Programming• Asynchronous communication and data streams
• reactive-streams.org
![Page 18: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/18.jpg)
Reactive Alternatives at Java EE
JMS EJB 3
Message-Driven Beans
Asynchronous Session Beans
CDIEvents
Observers
ServletAsynchronous
NIO
JAX-RSAsync on Server
Async on Client
WebSocket
Async Remote Endpoints Concurrency
Utilities
![Page 19: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/19.jpg)
Project Reactor• Library for building non-blocking apps • Interacts with Java 8 functional API • Offers two reactive composable API
• Flux[N] and Mono[0|1] • Supports scalable in-memory routing with Bus extensions
• Ported to support microservices
![Page 20: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/20.jpg)
REST Endpoint@RestControllerpublic class UserRestController {
private static final List<User> users = new ArrayList<>();
static { users.add(new User(1, "Rodrigo", "C", "da Silva")); users.add(new User(2, "Israel", "B", "Rodriguez")); users.add(new User(3, "Bruno", "", "Souza")); users.add(new User(4, "Edson", "", "Yanaga")); }
@RequestMapping(method = RequestMethod.GET, value = "/users") public List<User> getUsers() { return users; }
@RequestMapping(method = RequestMethod.GET, value = "/user/{id}") public User getUser(@PathVariable("id") Integer id) { return users.stream().filter(g -> g.getId() == id) .collect(Collectors.toList()).get(0); }
}
![Page 21: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/21.jpg)
REST Proxy@Componentpublic class UserServiceProxy {
@Autowired UserService service;
@HystrixCommand(fallbackMethod = "defaultUsersObservable") public Observable<List<User>> getUsersObservable() { return new ObservableResult<List<User>>() { @Override public List<User> invoke() { return service.getUsers(); } }; }
public Observable<User> defaultUsersObservable() { return null; }} @FeignClient("USER-SERVICE")
public interface UserService {
@RequestMapping(value = "/users", method = RequestMethod.GET) List<User> getUsers();
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET) User getUser(@PathVariable("id") Integer id);}
![Page 22: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/22.jpg)
REST Async Client
@RestControllerpublic class APIController {
@Autowired GroupServiceProxy groupService;
@Autowired UserServiceProxy userService;
@RequestMapping(method = RequestMethod.GET, value = "/userGroups") public UserGroup getUserGroups() { Observable<List<Group>> groups = groupService.getGroupsObservable(); Observable<List<User>> users = userService.getUsersObservable();
Observable<UserGroup> userGroupObservable = Observable.zip(groups, users, (g, u) -> new UserGroup(u, g));
return userGroupObservable.toList().toBlocking().single().get(0); }
}
![Page 23: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/23.jpg)
Demo• Reactive Microservices • https://github.com/rcandidosilva/reactive-microservices
![Page 24: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/24.jpg)
Other Alternatives
![Page 25: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/25.jpg)
Q&A
?
![Page 26: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/26.jpg)
References• http://projects.spring.io/spring-boot/ • http://projects.spring.io/spring-cloud/ • https://netflix.github.io/ • http://www.reactive-streams.org/ • http://www.reactivemanifesto.org/ • https://github.com/reactivemanifesto/website-manifesto/tree/master/public/pdf • https://projectreactor.io/ • http://reactivex.io/ • http://www.kennybastani.com/2016/04/event-sourcing-microservices-spring-
cloud.html
![Page 27: JavaOne 2016 - Reactive Microservices with Java and Java EE](https://reader031.vdocuments.net/reader031/viewer/2022021506/5882bdcc1a28abb2478b547d/html5/thumbnails/27.jpg)
Thank you! Obrigado!