Top Banner
#DevoxxUS Optimizing Enterprise Java for a Microservices Architecture John Clingan, middle-aged Java EE guy and MicroProfile-r Emily Jiang, totally awesome MicroProfile engineer Eclipse
27

MicroProfile Devoxx.us

Apr 11, 2017

Download

Software

jclingan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MicroProfile Devoxx.us

#DevoxxUS

Optimizing Enterprise Javafor a Microservices Architecture

John Clingan, middle-aged Java EE guy and MicroProfile-rEmily Jiang, totally awesome MicroProfile engineer

Eclipse

Page 2: MicroProfile Devoxx.us

#DevoxxUS

Agenda MicroProfile Overview (~10 Minutes)

Example Specs - From concept to implementation (10 minutes)

Collaborate (Until they kick us out or we want to go for a beer)

Page 3: MicroProfile Devoxx.us

#DevoxxUS

Enterprise Java Standards History

Page 4: MicroProfile Devoxx.us

#DevoxxUS

What is MicroProfile?

A community of individuals, organizations, and vendors …

… collaborating within an open source (Eclipse) project ….

… to bring microservices to the Enterprise Java community

Page 5: MicroProfile Devoxx.us

#DevoxxUS

Innovation vs Standardization

(Open Source) Project Focused Standard (JSR) focused

(Java EE)(MicroProfile)

Page 6: MicroProfile Devoxx.us

#DevoxxUS

Innovation vs Standardization

(Open Source) Project Focused Standard (JSR) focused

(Java EE)

Large multi-feature releasesIncremental feature release

(MicroProfile)

Page 7: MicroProfile Devoxx.us

#DevoxxUS

Innovation vs Standardization

Spec Lead controls pace

(Open Source) Project Focused Standard (JSR) focused

(Java EE)

Large multi-feature releasesIncremental feature release

(MicroProfile)

Community controls pace

Page 8: MicroProfile Devoxx.us

#DevoxxUS

Accelerating* Adoption of MicroServices

2016 2017 2018 2019

8 9

1.0

1.1

1.2

1.3

1.4

2020

1.5

* 2-4 releases per year

Page 9: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile 1.0 (Sep, 2016)

Contexts and Dependency Injection (CDI 1.1)

+

Java API for RESTful Web Services (JAX-RS 2.0)

+

Java API for JSON Processing (JSON-P 1.0)

Page 10: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile 1.1 Underway

Security: JWT Token Exchange 1.0

Health Check 1.0

Configuration 1.0

Fault Tolerance 1.0 (Stretch goal)

Second Quarter2017!

Page 11: MicroProfile Devoxx.us

#DevoxxUS

Will MicroProfile Features be in Java EE?

Possibly

Page 12: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Programming Model(In Progress)

● Config

● Fault Tolerance

● Health Checker

● Metrics

● Security

Page 13: MicroProfile Devoxx.us

#DevoxxUS

Configuration● Discussed with a formal proposal in the MicroProfile mailing list

(https://groups.google.com/forum/#!topic/microprofile/VJEEAOsVj5E[26-50])

● After the proposal was accepted, a repository was created to draft APIs/SPIs (https://github.com/eclipse/microprofile-config/)

Page 14: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog. Model - Configuration

Page 15: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog. Model - ConfigurationUsing CDI Injection

@Inject Config config; Inject all config properties that the class can see

@Inject @ConfigProperty(name=“myProp” defaultValue=“blah”)String prop1;

Inject the value of the property called “myProp”. The value of prop1 will not be refreshed. Suitable for static properties and used on the RequestScoped beans.

@Inject @ConfigProperty(name=“myProp” defaultValue=“blah”) Provider<String> prop1

Inject the value of the property called “myProp” and it picks up the dynamic changes.

Page 16: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog. Model - ConfigurationProgrammatic lookup

ConfigProvider.getConfig(); The config object containing all properties that the class owner can see.

ConfigProvider.getBuilder() .addDefaultSources() .withSources(…).build();

Create a custom config object

Page 17: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog. Model - Configuration● The property file, microprofile-config.properties, packaged in the application can be

overwritten by :○ System variables (400 as the default priority) ○ Environment variables (300 as the default priority) or ○ a custom property files with a higher priority than microprofile-config.properties

(100 as the default priority).

Page 18: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog. Model - config● Plan to finalise the current APIs/SPIs and release the Config 1.0

by mid April

● Then work on the new features of Config 1.1

● Join in the Config discussion

● Join in the Config hangout – on Thursdays

Page 20: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog model –Fault Tolerance

Retry The request should have a retry to recover from temporary glitches

Fallback The request should have a fallback operation if retry fails

Timeout The request must have a timeout, to prevent from waiting indefinitely

Circuit Breaker The request must prevent from repeating timeouts

Bulkhead One part of application failure must not bring the whole application down

Page 21: MicroProfile Devoxx.us

#DevoxxUS

Fault Tolerance - Fallback RetrySet up retry policy and wrap the call with the policy and specify the fallback operationFaultToleranceFactory.getFaultToleranceType(RetryPolicy.class);

Duration delay = Duration.ofSeconds(1);retryPolicy = retryPolicy.retryOn(Exception.class).withDelay(delay) .withMaxRetries(3);

Runnable fallbackService = () -> serviceB();executor.with(retryPolicy).withFallback(fallbackService) .run(mainService);

Page 22: MicroProfile Devoxx.us

#DevoxxUS

Fault Tolerance - Circuit Breaker TimeoutFail-fast, temporarily disable the running of a servicecircuitBreaker = FaultToleranceFactory.getFaultToleranceType(CircuitBreaker.class);circuitBreaker = circuitBreaker.withTimeout(timeout).withFailureThreshold(3) .withSuccessThreshold(2) .withDelay(delay);

Callable<Object> mainService = () -> serviceA();Executor executor = FaultToleranceFactory.getFaultToleranceType(Executor.class);

executor.with(circuitBreaker).get(mainService);

Page 23: MicroProfile Devoxx.us

#DevoxxUS

Fault Tolerance - BulkheadLimit the number of concurrent calls to a service

ThreadPoolExecutor tpexecutor = new ThreadPoolExecutor( poolSize, poolSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));

bulkhead = bulkhead.withThread(tpexecutor);executor.with(bulkhead) .run(mainService);

Page 24: MicroProfile Devoxx.us

#DevoxxUS

MicroProfile Java Prog model –Fault Tolerance

● Non-CDI approach was left out of the first release but focus on CDI-first approach

● Discussion the CDI-first approach ongoing● Use Interceptor to apply policy and use annotation to config policy

Page 25: MicroProfile Devoxx.us

#DevoxxUS

Health Check, Metrics, Security● Health Check – proposal accepted

● Metrics and Security – proposal in discussion

Page 26: MicroProfile Devoxx.us

#DevoxxUS

Join the Community!

Page 27: MicroProfile Devoxx.us

#DevoxxUS

Resources MicroProfile.io

MicroProfile Discussion Forumbit.ly/MicroProfileForum

MicroProfile Exampleshttps://github.com/microprofile/microprofile-samples