19
TECHNOLOGY SOLUTIONS DELIVERED Intro to Spring Boot and Spring Cloud OSS Twin Cities Cloud Foundry Meetup October 7, 2015 Josh Ghiloni (@joshghiloni)

Intro to Spring Boot and Spring Cloud OSS - Twin Cities Cloud Foundry Meetup

Embed Size (px)

Citation preview

TECHNOLOGY SOLUTIONS DELIVERED

Intro to Spring Boot and Spring Cloud OSSTwin Cities Cloud Foundry Meetup

October 7, 2015Josh Ghiloni (@joshghiloni)

Agenda• Intro to Spring Boot•Spring Cloud Origins•Why Spring Cloud?•External Configuration with Spring Cloud Config Server•Runtime Service Discovery with Eureka•Using Hystrix to Fail Gracefully•Demo!

Intro to Spring Boot• Accelerated Time to Market through:

• Embedded Container – Tomcat, Jetty, Undertow• No XML required! (insert joyful emoji here)• Production-ready features such as metrics, health checks and externalized

configuration – more on that last one a little later• Less boilerplate code

Most importantly, it is opinionated about how your app should work.

What's the difference between opinionated and unopinionated?

Intro to Spring Boot

Intro to Spring BootOK, so what's the deal with "less boilerplate code?" How about a fully functional Spring Boot app that fits inside a tweet (using Groovy):

@RestControllerclass WorkingBootApp {

@RequestMapping("/")def hello() {

[ message: "hello" ]}

}

Spring Cloud Origins

Why Spring Cloud?

Microservice architectures are complex!• They need to have their config stored in the environment, not in code• Microservices are loosely coupled – They need to discover and be discoverable• They are not necessarily colocated – Inter-service communication needs to be

fault-tolerant

Netflix is a microservice architecture … they (probably) didn't build all this just because they were bored

External Configuration with Spring Cloud Config Server

• Follow 12 Factor app development!

• Configuration stored in source control

• Extensible (store your config in a DB or LDAP or on punch cards)

• Securable (secure with whatever scheme you choose)

• Data can be stored encrypted at rest and decrypted on the fly (requires Unlimited JCE policy in Java buildpack)

@SpringBootApplication@EnableDiscoveryClient@EnableConfigServerpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run( ConfigServerApplication.class, args ); }}

Runtime Service Discovery with Eureka•Register and discover services at runtime

•Registrations stored in memory

•Simple dashboard available•Spring Boot autoconfiguration for self-registration

•Can be used to look up external config servers automatically

@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run( EurekaServerApplication.class, args ); }}

High Availability with Eureka

eureka-0 eureka-1 eureka-2 eureka-n

Route eureka

Using Hystrix to Fail Gracefully

source: http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

Using Hystrix to Fail Gracefully

source: http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

Including Spring Cloud in your Application@SpringBootApplication@EnableCircuitBreaker // for Hystrix@EnableDiscoveryClient // for Eureka@RestControllerpublic class MySpringCloudApplication { public static void main(String[] args) { SpringApplication.run(MySpringCloudApplication.class, args); } @RequestMapping("/") public String helloWorld() { return "Hello, World!"; }}

or…

Including Spring Cloud in your Application

@SpringCloudApplication@RestControllerpublic class MySpringCloudApplication { public static void main(String[] args) { SpringApplication.run(MySpringCloudApplication.class, args); } @RequestMapping("/") public String helloWorld() { return "Hello, World!"; }}

More Spring Cloud Integrations•Ribbon (Netflix) – Client Side Load Balancing•Zuul (Netflix) – Dynamic Routing•Feign (Netflix) – Declarative REST Client•Archaius (Netflix) – Client side configuration•Security – Single Sign on via OAuth2•Consul – Service Discovery•Zookeeper – Service Discovery

Demo!

Questions?

ReferencesTwelve Factor Apps: http://12factor.netMicroservice Prereqs: http://martinfowler.com/bliki/MicroservicePrerequisites.html Spring Boot: http://projects.spring.io/spring-boot/Spring Cloud: http://projects.spring.io/spring-cloud/ Netflix OSS: http://netflix.github.io/ Java Buildpack with Unlimited JCE: https://github.com/jghiloni/java-buildpack Source for this Demo: https://github.com/ECSTeam/spring-cloud-demo

Thank You!