Sei sulla pagina 1di 48

Eclipse MicroProfile para el desarrollador ocupado

Jorge Cajas - Vı́ctor Orozco


11 de Abril de 2019
@cajasmota - @tuxtor

1
Java EE - MicroProfile - Spring Boot - Docker

2
¿Microservicios?
¿Microservicios?

¿Necesito migrar todo a microservicios? ¿Que pasa


si no utilizo microservicios? ¿Me estoy volviendo
viejo?

3
Reactive applications

Aplicaciones reactivas

Microservicios son una (de muchas) herramienta para creación de


aplicaciones reactivas

4
Monolito - Escalabilidad

Figura 1: Monólito

5
ESB

Figura 2: ESB

6
Microservicios

Figura 3: Microservicios

7
Java EE 8
Java EE 8

8
Java EE 8

Java EE 8
• Integración JSF-CDI
• Integración JMS-CDI
• HTTP/2
• JSON-B
• Security
• JAX-RS Reactivo

9
Java EE 8 - Comunidad Java EE

10
Eclipse MicroProfile
Eclipse MicroProfile

Figura 4: Credito: Reza Rahman

11
Eclipse MicroProfile

12
Eclipse MicroProfile

13
Eclipse MicroProfile - Implementaciones

Bibliotecas
• SmallRye (Red Hat)
• Hammock
• Apache Geronimo
• Fujitsu Launcher
JEAS - Fat Jar
• Dropwizard
• KumuluzEE
• Helidon (Oracle)
• Open Liberty (IBM)
• Apache Meecrowave
• Thorntail (Red Hat)
• Quarkus (Red Hat)
14
Eclipse MicroProfile - Implementaciones

Micro server

• Payara Micro
• TomEE Plume

Full server

• Payara Application Server


• JBoss Application Server / Wildfly Application Server
• WebSphere Liberty (IBM)

https://wiki.eclipse.org/MicroProfile/Implementation

15
Eclipse MicroProfile on Payara 5

< dependency >


< groupId > org . eclipse . microprofile </ groupId >
< artifactId > microprofile </ artifactId >
< type > pom </ type >
< version >2.0.1 </ version >
< scope > provided </ scope >
</ dependency >

16
Config

17
Config

@Inject
@ConfigProperty(name = "omdbservice.url")
String o m d b D a e m o n ServiceUrl ;

Ext. de la configuración (VM, Docker, Kubernetes)

18
Fault Tolerance

19
Metrics

20
Fault Tolerance + Metrics

• Fault Tolerance depende de la existencia de metricas, las


metricas se exponen mediante Metrics

21
Fault tolerance

Reglas de evaluación y alternativas

• Circuit Breaker
• Bulkhead
• Retry
• Timeout
• Fallback

22
Fault tolerance - Fallback, Timeout

@GET
@Path ( " /{ id :[ a - z ]*[0 -9][0 -9]*} " )
@Fallback(fallbackMethod = "findByIdFallBack")
@Timeout(TIMEOUT)
public Response findById ( @PathParam ( " id " )
final String imdbId ) {
...
}

public Response findByIdFallBack ( @PathParam ( " id " )


final String imdbId ) {
...
}

23
Métricas

• JSON or OpenMetrics (Prometheus)


• Vendor
• Base
• Application

¿Cuales?

• Counted
• Gauge
• Metered
• Timed
• Histogram

24
Metrics - Counted
@Inject
@Metric
Counter failedQueries ;

@GET
@Path ( " /{ id :[ a - z ]*[0 -9][0 -9]*} " )
@Fallback(fallbackMethod = "findByIdFallBack")
@Timeout(TIMEOUT)
public Response findById ( @PathParam ( " id " )
final String imdbId ) {
...
}

public Response findByIdFallBack ( @PathParam ( " id " )


final String imdbId ) {
...
failedQueries.inc();
}
25
Metrics - Gauge

Inc-dec en tiempo real


@Gauge(unit = "ExternalDatabases",name = "movieDatabases", absolute
= true)
public long getDatabases () {
return 99; // Any value
}

/metrics/application/movieDatabases

26
Metrics - Metered

Events rate
@Metered ( name = " moviesRetrieved " ,
unit = MetricUnits . MINUTES ,
description = " Metrics to monitor movies " ,
absolute = true )
public Response findExpandedById (
@PathParam ( " id " ) final Long id )

/metrics/application/movieDatabases

27
Metrics- Timed

Desempeño y retraso
@Timed ( name = " moviesDelay " ,
description = " Time to retrieve a movie " ,
unit = MetricUnits . MINUTES ,
absolute = true )
public Response findExpandedById (
@PathParam ( " id " ) final Long id )

/metrics/application/moviesDelay

28
Metrics - Histogram

Distribuciones
@Inject
MetricRegistry registry ;

@POST
@Path ( " / add /{ attendees } " )
public Response addAttendees (
@PathParam ( " attendees " ) Long attendees ) {
Metadata metadata =
new Metadata ( " matrix attendees " ,
MetricType . HISTOGRAM );
Histogram histogram =
registry . histogram ( metadata );
histogram . update ( attendees );
return Response . ok (). build ();
}

29
Health Check

30
Health Check

¿Estas vivo?
@Override
public H ea l t hC h e ckResponse call () {
return He althCheckResponse . named ( " TaVivoAinda " )
. withData ( " key1 " , " val1 " )
. withData ( " key2 " , " val2 " )
. up ()
. build ();

31
JWT

32
JWT

@LoginConfig(authMethod = "MP-JWT")
public class Ap plicationConfig extends Application {
}

@Inject
private JsonWebToken jwtPrincipal ;

@Inject
@Claim("email")
private String email ;

33
TypeSafe

34
TypeSafe

@Path ( " / playlist " )


@Consumes ( " application / json " )
public interface M usicPlaylistService {

@GET
List < String > getPlaylistNames ();

@PUT
@Path ( " /{ playlistName } " )
long updatePlayList ( @PathParam ( " playlistName " )
String name ,
List < Song > playlist )
throws U nk n o w nP l a y li s t E xc e p t io n ;
}

35
Demo
EE + MicroProfile - Demo

Java 8, JAX-RS, CDI, EJB,


MicroProfile
https://github.com/tuxtor/payara-demo
https://github.com/tuxtor/omdb-demo

36
Payara Micro - Java EE 8

Stacks tradicionales

• EJB
• JTA
• JAX-RS
• CDI

37
EE + MicroProfile - Demo
MicroProfile: JAX-RS, CDI, Config, Fault Tolerance, Metrics
Payara Micro: EJB, JTA
Fatores externos: Location, Deployment, Orchestation, Balancing, Consistency

38
12 factores cloud native (Heroku)

Microprofile Cloud
• Config • Codebase (Git-Flow)
• Backing service • Dependencies (Maven)
• Disposability • Build, Release, Run
• Processes (Pipelines)
• Port binding
• Concurrency (Docker - k8s)
• Dev / Prod parity
• Logs
• Admin process

39
Oracle Cloud

40
Oracle Cloud

41
Oracle Cloud

42
Oracle Cloud

43
Vı́ctor Orozco

• me@vorozco.com
• @tuxtor
• http://vorozco.com
• http://tuxtor.shekalug.org

This work is licensed under a


Creative Commons
Attribution-ShareAlike 3.0.

44

Potrebbero piacerti anche