Build resilient Java Microservices with Eclipse MicroProfile Emily Jiang, Liberty Architect for MicroProfile and CDI, IBM @emilyfhjiang Antoine Sabot-Durand, Senior Software Engineer on MicroProfile and CDI Spec Lead, Red Hat @antoine_sd Emily Jiang – MicroProfile Development Lead @emilyfhjiang Emily starts the presentation and introduce herself. Antoine will then introduce himself.
What are Microservices? Small concise service – small piece of SOA Easy to maintain Easy to release Loosely coupled; A number of them to form a system Microservice best practice Configurable Fault tolerance Monitoring Secure Working well in the cloud How to build it the right way? Use Eclipse MicroProfile Use Spring but more complex Emily talks about Microservice and MicroProfile.
Antoine: Thorntail (formerly known as WildFly Swarm) isn't there yet, probably because it has changed to develop MP specs separately as SmallRye so the implementations can be included in both WildFly and Thorntail. You can see the progress of SmallRye here: https://www.smallrye.io/projects/overview Tomitribe recently announced TomEE 7.1 and their intention to keep adding more MicroProfile specs very soon: https://www.tomitribe.com/blog/2018/09/tomee-an-overview-of-the- tomee-7-1-release/ https://twitter.com/dblevins/status/1039271997245673472 Oracle have *very* recently uncovered Helidon, which is starting at MicroProfile 1.1 and will add more features from there: https://medium.com/oracledevs/helidon-takes-flight-fb7e9e390e9c Fujitsu announced Launcher a long time ago, but there is no word (that I have seen) on how they will proceed. They are derived from GlassFish, like Payara, so whether they will collaborate with Payara or SmallRye remains to be seen: https://github.com/fujitsu/launcher KumuluzEE announced support for MP 1.2 a while ago, but I haven't seen much since then: https://ee.kumuluz.com/microprofile Beyond those, there are a couple of smaller implementations which implement a few specs: Hammock by John Ament is due a 1.2 release soon (according to the website: https://hammock-project.github.io) There's also GuardEE by Matthieu Brouillard which, I think, supports just Config and Fault Tolerance: https://github.com/McFoggy/GuardEE I think that about covers everything! If you want 2.0 *now* you'll need OpenLiberty or Payara Micro/Payara Server. For the near future, keep an eye on: Thorntail and WildFly (both using SmallRye); TomEE 8.0; Oracle Helidon.
What does MicroProfile do? Vendor-neutral programming model, designed in the open, for Java microservices Provide core capabilities for building fault tolerant, scalable, microservices Increasing the rate and pace of innovation beyond Java EE Standardizing microservices in enterprise Java via the MicroProfile community Config Fault Tolerance Health Check Metrics Security (JWT) Open Tracing Open API Rest Client externalize configuration to improve portability build robust behavior to cope with unexpected failures ensure services are running and meeting SLAs understand the interactions between services while running provides role based access control (RBAC) for microservice endpoints Tracing the microservices invocation chain Easily document microservcie APIs Simplify the creation of rest clients See http://microprofile.io/ Graphic shows the community members for MicroProfile who are contributing to the technical direction and development of core capabilities that MicroProfile offers. These form the essential building blocks of microservices and are currently absent from the Java EE specification. By taking a community driven approach to their development, the broader Java developer community can increase the rate and pace of innovation, and prove the technology through the community prior to offering the capabilities to Oracle to standardizes as part of a future Java EE specification. As MicroProfile is an open source Eclipse project, multiple vendors provide implementations of the MicroProfile specification following the tradition of Java EE itself which provides a vendor neutral specification for enterprise application development. This helps optimize the portability of apps built using the MicroProfile specification and avoids vendor lock-in. Invite developers to join the MicroProfile community and influence the future http://microprofile.io/
MicroProfile 2.1 release JSON-P 1.1 JAX-RS 2.1 Config 1.3 CDI 2.0 Open Tracing 1.2 Open API 1.0 Rest Client 1.1 JSON-B 1.0 Fault Tolerance 1.1 JWT Propagation 1.0 Metrics 1.1 JWT 1.1 Health Check 1.0 JSON-P 1.1 JAX-RS 2.1 Config 1.3 CDI 2.0 Antoine to talk MicroProfile 2.1 = New = Updated = No change from last release
Fault tolerance is about leveraging different strategies to guide the execution and result of some logic. Retry policies, bulkheads, and circuit breakers are popular concepts in this area. They dictate whether and when executions should take place, and fallbacks offer an alternative result when an execution does not complete successfully Antoine to talk
CircuitBreaker - @CircuitBreaker Bulkhead - @Bulkhead @Asynchronous Fault tolerance policies based on CDI interceptor are applied with the following annotations: Retry - @Retry Timeout - @Timeout CircuitBreaker - @CircuitBreaker Bulkhead - @Bulkhead @Asynchronous Fallback - @Fallback Emily to talk
Retry: Transient Failure service A Service B for (int i = 0; i < 5; i++) { try { callServiceC(); break; } catch (IOException e) { } } Emily
Retry: Transient Failure service A service B @Retry(retryOn=IOException.class, delay = 500, maxRetries=5) public void callServiceC() { // call the service } Emily
Timeout: Dealing with slow services service A service B 5s SLA 5s response @Timeout(2000) public void callServiceC() { // call the service } Emily
Bulkhead: Restrict resources service A service B @Bulkhead public void callServiceC() { // call the service } Emily @Bulkhead @Asynchronous public void callServiceC() { // call the service }
CircuitBreaker: Closed service A service B Antoine
CircuitBreaker: Open service A service B Antoine
CircuitBreaker: Half-Open service A service B @CircuitBreaker(failOn=IOException.class, delay = 500) public void callServiceC() { // call the service } Antoine
Fallback: handler service A service B @Fallback(MyFallback.class) public void callServiceC() { // call the service } private class MyFallback implements FallbackHandler { public void handle(ExecutionContext c) { // perform fallback action } Antoine
Fallback: method service A service B @Fallback(fallbackMethod="fallback")public void callServiceC() { // call the service } public void fallback() { //do something Antoine
MicroProfile Fault Tolerance with Istio @Retry @Timeout @CircuitBreaker @Bulkhead @Fallback Retry Timeout CircuitBreaker Bulkhead Emily MicroProfile Fault Tolerance offers Retry, Timeout, Bulkhead, CircuitBreaker, Fallback Istio offers Failure handling: Timeout, retries, limits on number of concurrent connections, circuit breakers Istio can not offer fallback Microservices need both of them sometimes How to set up a ecosystem of MicroProfile Fault Tolerance with Istio Use MicroProfile Fault Tolerance without Istio’s Fault Handling Use Istio’s Fault Handling with MicroProfile Fault Tolerance fallback MicroProfile Fault Tolerance is configurable and flexible The Fault Tolerance policies except fallback can be switched off via a configuration property called MP_Fault_Tolerance_NonFallback_Enabled with the value of false. Unique feature from MicroProfile Fault Tolerance where other Fault Tolerance third party libraries cannot offer easily
Demo ServiceA: resilient ServiceB: unreliable Open Liberty Use MicroProfile RestClient Register Client @RegisterRestClient Inject the client @Inject @RestClient MyClient myClient; Bind the client <fully-qualified classname>/mp-rest/url=<backend-service-url>
Configure Fault Tolerance parameters parameters test Configure Fault Tolerance parameters parameters test.ServiceAEndpoint/callserviceB/Retry/maxRetries=5 test. ServiceAEndpoint/callServiceB/Retry/delay=400 test.ServiceAEndpoint/Fallback/fallbackMethod=”anotherFall” test.ServiceAEndpoint/Retry/enabled=false Retry/enabled=false
Monitor Fault Tolerance – since FT 1.1 Merics added for Retry, Timeout, CircuitBreaker, Bulkheader and fallback Retry: callsSuccededNotRetires.total, callsSuccededRetired.total, callsFailed.total, retires.total Timeout: executionDuration, callsTimedOut.total, callsNotTimedOut.total CircuitBreaker: circuitbreaker.callsSucceeded.total, circuitbreaker.calls.Failed.total, circuitbreaker.calls.Prevented.total, circuitbreaker.open.total, circuitbreaker.halfOpen.total, circuitbreaker.closed.total, circuitbreaker.opened.total Bulkhead: concurrentExecutions, callsAccepted.total, callsRejected.total, executionDuration, bulkhead.waitingQueue.population, bulkhead.waiting.duration Fallback: fallback.calls.total All of the above metrics name prefixd with ft.<packagename>
Resources http://microprofile.io/ https://openliberty.io/ https://thorntail.io https://openliberty.io/guides/circuit-breaker.html https://www.eclipse.org/community/eclipse_newsletter/2017/september/ Code Demo https://github.com/Emily-Jiang/demo-ft-service-a https://github.com/Emily-Jiang/demo-ft-service-b http://mp-starter-jessie.1d35.starter-us-east-1.openshiftapps.com/mp-starter/
IBM Java Community Party! Coin-Op Game Room 508 4th Street San Francisco, CA 94107 Wed, October 24, 2018 7:30 PM – 11:00 PM PDT IBM Java Community Party! After Community Keynote We'll be hosting drinks, light food, and video game quarters to help everyone unwind. Chill in the quiet room, or challenge your friends to an epic Pacman Battle Royale! Tell your boss it's "brainstorming". Space is limited, RSVP is required for attendance. https://www.eventbrite.com/e/ibm-java-community-party-tickets-51556807800