Slide 1

Slide 1 text

Microservices for the Masses with Spring Boot, JHipster, and OAuth March 11, 2020 Matt Raible | @mraible Photo by Tambako The Jaguar flickr.com/photos/tambako/4580951085

Slide 2

Slide 2 text

Do you use microservices?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Agenda 1. Introduction to Microservices 2. Microservices with JHipster 3. Deploying to the Cloud 4. JHipster Roadmap

Slide 5

Slide 5 text

Blogger on raibledesigns.com and developer.okta.com/blog Web Developer and Java Champion Father, Husband, Skier, Mountain Biker, Whitewater Rafter Open Source Connoisseur Hi, I’m Matt Raible! Bus Lover Okta Developer Advocate

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

developer.okta.com

Slide 9

Slide 9 text

What About You?

Slide 10

Slide 10 text

Part 1 Introduction to Microservices History of Microservices Microservices Architecture Philosophy Why Microservices? Demo: A Microservices Architecture with Spring Boot and Spring Cloud

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Microservices Visionaries

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

“Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.” Conway’s Law Melvin Conway 1967

Slide 15

Slide 15 text

“Do one thing and do it well.”

Slide 16

Slide 16 text

“You shouldn't start with a microservices architecture. Instead begin with a monolith, keep it modular, and split it into microservices once the monolith becomes a problem.” Martin Fowler March 2014

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

start.spring.io

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Demo Using start.spring.io, create: A service registry A gateway A catalog service Create an endpoint in the catalog service Create a filtered endpoint in the gateway Show failover capabilities Show Spring Security OAuth https://github.com/oktadeveloper/java- microservices-examples

Slide 22

Slide 22 text

Create Java Microservices using start.spring.io http https://start.spring.io/starter.zip javaVersion==11 \ artifactId==discovery-service name==eureka-service \ dependencies==cloud-eureka-server baseDir==discovery-service \ | tar -xzvf -

Slide 23

Slide 23 text

Enable Eureka Server & Configure application.properties server.port=8761 eureka.client.register-with-eureka=false @EnableEurekaServer

Slide 24

Slide 24 text

Create Car Service http https://start.spring.io/starter.zip \ artifactId==car-service name==car-service baseDir==car-service \ dependencies==actuator,cloud-eureka,data-jpa,h2,data- rest,web,devtools,lombok | tar -xzvf -

Slide 25

Slide 25 text

Enable Discovery & Configure application.properties server.port=8090 spring.application.name=car-service @EnableDiscoveryClient

Slide 26

Slide 26 text

Create API Gateway http https://start.spring.io/starter.zip \ artifactId==api-gateway name==api-gateway baseDir==api-gateway \ dependencies==cloud-eureka,cloud-feign,data-rest,web,cloud- hystrix,lombok | tar -xzvf -

Slide 27

Slide 27 text

Enable Discovery & Configure application.properties spring.application.name=api-gateway @EnableDiscoveryClient

Slide 28

Slide 28 text

Build a REST API in Car Service @Data @NoArgsConstructor @Entity class Car { public Car(String name) { this.name = name; } @Id @GeneratedValue private Long id; @NonNull private String name; }

Slide 29

Slide 29 text

Build a REST API in Car Service @RepositoryRestResource interface CarRepository extends JpaRepository { }

Slide 30

Slide 30 text

Build a REST API in Car Service @Bean ApplicationRunner init(CarRepository repository) { return args -> { Stream.of("Ferrari", "Jaguar", "Porsche", "Lamborghini", "Bugatti", "AMC Gremlin", "Triumph Stag", "Ford Pinto", "Yugo GV").forEach(name -> { repository.save(new Car(name)); }); repository.findAll().forEach(System.out::println); }; }

Slide 31

Slide 31 text

Consume Cars API in Gateway @EnableFeignClients @EnableCircuitBreaker @EnableDiscoveryClient @SpringBootApplication public class ApiGatewayApplication { public static void main(String[] args) { SpringApplication.run(ApiGatewayApplication.class, args); } }

Slide 32

Slide 32 text

Consume Cars API in Gateway @Data class Car { private String name; } @FeignClient("car-service") interface CarClient { @GetMapping("/cars") @CrossOrigin CollectionModel readCars(); }

Slide 33

Slide 33 text

Consume Cars API in Gateway @RestController class CoolCarController { private final CarClient carClient; public CoolCarController(CarClient carClient) { this.carClient = carClient; } // code on next slide }

Slide 34

Slide 34 text

Consume Cars API in Gateway private Collection fallback() { return new ArrayList<>(); } @GetMapping("/cool-cars") @CrossOrigin @HystrixCommand(fallbackMethod = "fallback") public Collection goodCars() { return carClient.readCars() .getContent() .stream() .filter(this::isCool) .collect(Collectors.toList()); }

Slide 35

Slide 35 text

Consume Cars API in Gateway private boolean isCool(Car car) { return !car.getName().equals("AMC Gremlin") && !car.getName().equals("Triumph Stag") && !car.getName().equals("Ford Pinto") && !car.getName().equals("Yugo GV"); }

Slide 36

Slide 36 text

Start everything with ./mvnw

Slide 37

Slide 37 text

Access https://localhost:8080/cool-cars

Slide 38

Slide 38 text

Java Microservices with Spring Boot and Spring Cloud https://developer.okta.com/blog/2019/05/22/java-microservices-spring-boot-spring-cloud

Slide 39

Slide 39 text

Microservices with JHipster What is JHipster? Installing and Using JHipster JHipster’s Microservice Features Progressive Web Applications Overview Part 2

Slide 40

Slide 40 text

What is JHipster? + =

Slide 41

Slide 41 text

JHipster jhipster.tech JHipster is a development platform to generate, develop and deploy Spring Boot + Angular/React Web applications and Spring microservices. and Vue! ✨

Slide 42

Slide 42 text

JHipster is Inclusive https://github.com/jhipster/jhipster-artwork

Slide 43

Slide 43 text

A powerful workflow to build your application with Webpack and Maven/Gradle JHipster Goals A sleek, modern, mobile-first front-end with modern frameworks A high-performance and robust Java stack on the server side with Spring Boot A robust microservice architecture with JHipster Registry, Netflix OSS, Elastic Stack, and Docker

Slide 44

Slide 44 text

How to Use JHipster Install JHipster and Yeoman, using npm: npm install -g generator-jhipster Create a directory and cd into it: mkdir newapp && cd newapp Run it! jhipster

Slide 45

Slide 45 text

Microservices with JHipster

Slide 46

Slide 46 text

https://www.jhipster.tech/microservices-architecture

Slide 47

Slide 47 text

yelp.com/callback Back to redirect URI with authorization code Exchange code for access token and ID token accounts.google.com Email ********** Go to authorization server Redirect URI: yelp.com/cb Scope: openid profile Authorization Server yelp.com Connect with Google Resource owner Client accounts.google.com Allow Yelp to access your public profile and contacts? No Yes Request consent from resource owner Hello Matt! accounts.google Get user info with access token /userinfo OAuth 2.0 and OIDC

Slide 48

Slide 48 text

Monolith Examples JHipster 6 Demo github.com/mraible/jhipster6-demo youtu.be/uQqlO3IGpTU 21-Points Health github.com/mraible/21-points infoq.com/minibooks/jhipster-mini-book

Slide 49

Slide 49 text

Progressive Web Apps Originate from a secure origin, load while offline, and reference a web app manifest.

Slide 50

Slide 50 text

Progressive Web Apps Can be installed on your mobile device, look and act like a native application, but are distributed through the web.

Slide 51

Slide 51 text

Progressive Web Apps Are fast!

Slide 52

Slide 52 text

“We’ve failed on mobile.” Alex Russell https://youtu.be/K1SFnrf4jZo

Slide 53

Slide 53 text

Enable PWA in JHipster if ('serviceWorker' in navigator) { window.addEventListener('load', function() { navigator.serviceWorker.register('/service-worker.js') .then(function () { console.log('Service Worker Registered'); }); }); } gateway/src/main/webapp/index.html

Slide 54

Slide 54 text

Force HTTPS in Spring Boot gateway/src/main/java/com/okta/developer/gateway/config/SecurityConfiguration.java @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.requiresChannel() .requestMatchers(r -> r.getHeader("X-Forwarded-Proto") != null) .requiresSecure(); } } https://developer.okta.com/blog/2018/07/30/10-ways-to-secure-spring-boot

Slide 55

Slide 55 text

Demo Using JHipster, create: A gateway A store microservices app A blog microservices app Generate entities in apps and on gateway Convert gateway to be a PWA Run everything in Docker https://github.com/oktadeveloper/java- microservices-examples

Slide 56

Slide 56 text

JHipster 6.8.0 Lighthouse Report

Slide 57

Slide 57 text

Part 3 Deploy to the Cloud Options for Deploying JHipster Heroku Cloud Foundry AWS Google Cloud Microsoft Azure

Slide 58

Slide 58 text

For monoliths: jhipster heroku For microservices: Deploy JHipster Registry Build and deploy microservice Build and deploy gateway http://bit.ly/heroku-jhipster-microservices

Slide 59

Slide 59 text

For monoliths: jhipster cloudfoundry For microservices: Deploy JHipster Registry Build and deploy microservice Build and deploy gateway https://www.jhipster.tech/cloudfoundry/

Slide 60

Slide 60 text

Using Elastic Container Service jhipster aws-containers Using Elastic Beanstalk jhipster aws Boxfuse boxfuse run -env=prod http://www.jhipster.tech/aws http://www.jhipster.tech/boxfuse

Slide 61

Slide 61 text

mvn package -Pprod jib:dockerBuild jhipster kubernetes ./kubectl-apply.sh kubectl get svc gateway https://developer.okta.com/blog/2017/06/20/ develop-microservices-with-jhipster

Slide 62

Slide 62 text

Part 4 JHipster Roadmap What You Learned What’s Next for JHipster

Slide 63

Slide 63 text

What You Learned

Slide 64

Slide 64 text

Microservices with Spring Cloud Config and JHipster https://developer.okta.com/blog/2019/05/23/java-microservices-spring-cloud-config

Slide 65

Slide 65 text

JHipster Mobile Apps and Microservices on Pluralsight pluralsight.com/courses/play-by-play-developing-microservices-mobile-apps-jhipster

Slide 66

Slide 66 text

What’s Next for JHipster? Full Reactive with WebFlux and Spring Cloud Gateway Spring Boot 2.2 GraphQL and Micro Frontends

Slide 67

Slide 67 text

The JHipster Mini-Book Written with Asciidoctor Free download from InfoQ: infoq.com/minibooks/jhipster-mini-book Quick and to the point, 164 pages Developed a real world app: www.21-points.com Buy for $20 or download for FREE

Slide 68

Slide 68 text

Learn More stackoverflow.com Spring Boot spring.io/guides JHipster www.jhipster.tech Okta APIs developer.okta.com

Slide 69

Slide 69 text

developer.okta.com/blog @oktadev

Slide 70

Slide 70 text

Reactive Microservices with Spring Cloud Gateway https://developer.okta.com/blog/2019/08/28/reactive-microservices-spring-cloud-gateway

Slide 71

Slide 71 text

Action: Try JHipster! https://developer.okta.com/blog/2019/04/04/java-11-java-12-jhipster-oidc

Slide 72

Slide 72 text

git clone https://github.com/oktadeveloper/okta-spring-webflux-react- example.git https://github.com/oktadeveloper/java-microservices-examples Use the Source, Luke!

Slide 73

Slide 73 text

Thanks! Keep in Touch raibledesigns.com @mraible Presentations speakerdeck.com/mraible Code github.com/oktadeveloper developer.okta.com

Slide 74

Slide 74 text

developer.okta.com