Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Cloud-ready Micro Java EE 8

A presentation given at Cloud-native nerd meetup in Munich 2017.

Abstract: One of the key challenges of breaking up monoliths into microservices is orchestration. This presentation looks at some of the brand-new features and APIs in Java EE 8 and MicroProfile that can help. It presents how easily messaging can be made cloud-ready and how your Java EE based microservices can be so lightweight with Payara Micro to run them on low-cost clusters.

  • Loggen Sie sich ein, um Kommentare anzuzeigen.

Cloud-ready Micro Java EE 8

  1. 1. Cloud-ready Micro Java EE 8 Ondro Mihályi | Payara Engineer | @omihalyi | @Payara_Fish
  2. 2. Who am I? • Payara Engineer • Java EE developer and lecturer • Conference speaker • Czech JUG leader • Member of JCP and Eclipse foundation • @omihalyi
  3. 3. What’s this all about? • How lightweight is Java EE, really? • What’s in Java EE 8 today? • What could be in Java EE EE4J ??? in the future?
  4. 4. A little (recent) history... • 12 June 2013: Java EE 7 Released •Docker was 3 months old •WildFly was still JBoss AS (and no Swarm) •Before Spring Boot •WebSphere Liberty Profile recently released
  5. 5. A little (recent) history... • 21 September 2017: Java EE 8 Released, 4 years later •Docker is now the dominant container format •WildFly have fully product-ised WildFly Swarm •Spring Boot have been making JARs not WARs for a few years •IBM released Open Liberty •Payara entered the fray and released Payara Micro •Eclipse MicroProfile is established and progressing
  6. 6. What’s in Java EE 8? • Upgrades •JAX-RS 2.1 •Servlet 4.0 •Bean Validation 2.0 •JSF 2.3 •CDI 2.0 •JSON-P 1.1 • New •Java EE Security •JSON-B
  7. 7. What is Payara Micro? • Payara Micro is… •Micro! (~60MB disk size, ~30 MB RAM) •Dynamically scalable •Fully embeddable (if you want…) •Web Profile “plus” •On Maven Central <dependency> <groupId>fish.payara.api</groupId> <ArtifactId>payara-api</artifactId> <version>5.0.0-Alpha3</version> <type>jar</type> </dependency>
  8. 8. What is Payara Micro? • Key APIs • Servlets, JSTL, EL, JSP • WebSockets • JSF • JAX-RS • EJB Lite • JTA • JPA • JCA (pluggable JMS) • Bean Validation • CDI • Interceptors • JBatch • Concurrency • JCache • Config • SOAP, remote EJB
  9. 9. Demo
  10. 10. Demo Scenario • Stock! Micro Stock! • Publish StockTicker events • Listen on different endpoints
  11. 11. Demo Scenario StockTickerStockTickerStockTicker Produces Events StockWeb Consumes Events Websocket Push
  12. 12. Demo 1 Creating the Stock Ticker • What do we need? • Stock object • Stock Ticker to set the stock price • Publisher for CDI event bus
  13. 13. Demo 2 Creating the Stock Web listener • What do we need? • Websocket endpoint • Class to manage Websocket sessions • Class to listen for Stock events on the CDI event bus • Both these responsibilities can be in the same class
  14. 14. Integrating Java EE 8 Features
  15. 15. Demo Making our MicroService generic • What do we need to change? • Non-Payara services can’t listen on the CDI event bus • Solution: REST Server Sent Events (from JAX-RS 2.1) • External services may not have access to a Stock object (or interface) • Solution: Serialise our Stock object as JSON using JSON-B 1.0
  16. 16. private JsonObject toJson() { JsonObjectBuilder objectBuilder = Json.createObjectBuilder() .add("symbol", symbol) .add("description", description) .add("price", price); return objectBuilder.build(); } @Override public String toString() { return this.toJson().toString(); } Demo 3 JSON-P manual toJson() method
  17. 17. @JsonbNillable public class Stock implements Serializable { private String symbol; @JsonbTransient private String description; @JsonbProperty("RandomPrice") private double price; @Override public String toString() { JsonbConfig nillableConfig = new JsonbConfig().withNullValues(true); return JsonbBuilder.create(nillableConfig).toJson(this); } } private void observe() { source.register((sseEvent) -> { this.stock = JsonbBuilder.create().fromJson(sseEvent.readData(), Stock.class); }); source.open(); } Demo 3 JSON-B serialisation and deserialisation Learn more: http://json-b.net
  18. 18. private void reactiveClient() { CompletionStage<Response> cs1 = ClientBuilder.newClient() .target("http://localhost:8080/jax-rs-2-1/books") .request() .rx() .get(); CompletionStage<Response> cs2 = ClientBuilder.newClient() .target("http://localhost:8080/jax-rs-2-1/magazines") .request() .rx() .get(); cs1.thenCombine(cs2, (r1, r2) -> r1.readEntity(String.class) + r2.readEntity(String.class)) .thenAccept(System.out::println); } Source: https://www.ibm.com/developerworks/library/j-whats-new-in-javaee-8/index.html Author: Alex Theedom Demo 4 JAX-RS reactive client API
  19. 19. Demo 4 SSE server endpoint in JAX-RS @GET @Produces(MediaType.SERVER_SENT_EVENTS) public void eventOutput(@Context SseEventSink eventSink){ // send a single event eventSink.send(sse.newEvent(stockTicker.getStock().toString())); // registers the requester as a consumer of events sseBroadcaster.register(eventSink); } @POST @Path("broadcast") @Consumes(MediaType.MULTIPART_FORM_DATA) public void broadcast(@FormParam("event") String event){ // broadcasts the event to all registered consumers sseBroadcaster.broadcast(sse.newEvent(event)); }
  20. 20. Demo 4 StockTickerStockTickerStockTicker StockWeb JAX-RS SSE Client Javascript SSE Client
  21. 21. The Future of Java EE…?
  22. 22. Demo 5 Integrating MicroProfile 1.1 <dependency> <groupId> org.eclipse.microprofile </groupId> <artifactId> Microprofile-bom </artifactId> <version>1.1.0</version> <type>pom</type> <scope>provided</scope> </dependency> @Inject @ConfigProperty(name = "stockticker.url") private String stockTickerURL; @Inject @ConfigProperty(name = "stockticker.url") private Instance<String> tickerURLConfig; ... String url = tickerURLConfig.get()
  23. 23. Demo 5 Integrating MicroProfile // Set system property java -jar -Dstockticker.url=http://localhost:8081/StockTicker-1.0-SNAPSHOT/rest/sse StockWeb/target/StockWeb- 1.0-SNAPSHOT-microbundle.jar // Use asadmin to set property in Hazelcast cluster asadmin> set-config-property --propertyName=stockticker.url --propertyValue=http://localhost:8080/StockTicker-1.0-SNAPSHOT/rest/sse --source=cluster // Use asadmin to set property for specific instances in Hazelcast cluster asadmin> send-asadmin-command --targets=‘*‘ --command=set-config-property -- --propertyName=stockticker.url --propertyValue=http://localhost:8080/StockTicker-1.0-SNAPSHOT/rest/sse --source=config --sourceName=sever-config
  24. 24. Recap •Java EE is incredibly adaptable to changing needs • Recent change has been driven by vendors’ implementations • Eclipse MicroProfile offers interesting ideas for the future
  25. 25. Thank you!