Top Banner
Micro Service Micro Service Architecture Architecture with Spring Boot, Groovy and Friends with Spring Boot, Groovy and Friends Spring Boot with Groovy and Friends http://localhost/spring-boot/#/ 1 of 33 10/09/14 21:54
33

Micro Service Architecture with Spring Boot and Groovy

Jun 14, 2015

Download

Software

Spring IO

Speaker: Marco Vermeulen
Spring Boot is a new addition to the Spring family. It takes an opinionated view of building Spring applications, adopting Convention Over Configuration by default. Add Groovy to the mix, and you have a web stack that will give you wings!
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: Micro Service Architecture with Spring Boot and Groovy

Micro ServiceMicro Service

ArchitectureArchitecturewith Spring Boot, Groovy and Friendswith Spring Boot, Groovy and Friends

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

1 of 33 10/09/14 21:54

Page 2: Micro Service Architecture with Spring Boot and Groovy

About MeAbout Me

Marco VermeulenMarco Vermeulen

Love Coding!Worked for Shazam, Associated Newspapers, Burberry, VisaCurrent: Equal Experts at HMRCCreator of GVM (Groovy enVironment Manager)Blog: Twitter:

Wired for Code@marcoVermeulen

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

2 of 33 10/09/14 21:54

Page 3: Micro Service Architecture with Spring Boot and Groovy

The TalkThe Talk

ConceptsMicro Service ArchitectureSpring & Spring BootSpring Boot Components

DemoGradleCucumber, SpockSpring Boot & GroovySpring Data & MongoDB

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

3 of 33 10/09/14 21:54

Page 4: Micro Service Architecture with Spring Boot and Groovy

About the DemoAbout the Demo

Invader ZimInvader Zim

American CartoonCreated by Jhonen VasquezOn Nickelodeon from March, 2001Discontinued, with Cult following!Theme of IMPENDING DOOM!Characters: Zim and GIR

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

4 of 33 10/09/14 21:54

Page 5: Micro Service Architecture with Spring Boot and Groovy

About the DemoAbout the Demo

Invader ZimInvader Zim

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

5 of 33 10/09/14 21:54

Page 6: Micro Service Architecture with Spring Boot and Groovy

Zim and GIRZim and GIR

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

6 of 33 10/09/14 21:54

Page 7: Micro Service Architecture with Spring Boot and Groovy

Micro Service ArchitectureMicro Service Architecture

-- James Lewis :

..how we designed and built a Resource Oriented, Event DrivenSystem out of applications about 1000 lines long...

Java, the Unix Way

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

7 of 33 10/09/14 21:54

Page 8: Micro Service Architecture with Spring Boot and Groovy

Micro Service ArchitectureMicro Service Architecture

Small with Single ResponsibilitySmall with Single Responsibility

Many small apps, not monolithicSingle functionFew hundred lines of codeEasy to bin and rewrite!

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

8 of 33 10/09/14 21:54

Page 9: Micro Service Architecture with Spring Boot and Groovy

Micro Service ArchitectureMicro Service Architecture

Containerless Unix ProcessContainerless Unix Process

Embedded ContainerExecutable FatJarInstall with Package Manager (RPM/DEB)Use unix service scripts

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

9 of 33 10/09/14 21:54

Page 10: Micro Service Architecture with Spring Boot and Groovy

Micro Service ArchitectureMicro Service Architecture

Dedicated VCS rootsDedicated VCS roots

Separate Repo per appOkay to duplicate domains!Common modules can be extracted

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

10 of 33 10/09/14 21:54

Page 11: Micro Service Architecture with Spring Boot and Groovy

Micro Service ArchitectureMicro Service Architecture

Status Aware and Auto-ScalingStatus Aware and Auto-Scaling

In-app MetricsPing and Health ChecksExternal watchdog processScale on demand

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

11 of 33 10/09/14 21:54

Page 12: Micro Service Architecture with Spring Boot and Groovy

FrameworksFrameworks

Lots of choices!Lots of choices!

SinatraPlayDjangoDrop WizardVertxGrailsRatpackSpring Boot

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

12 of 33 10/09/14 21:54

Page 13: Micro Service Architecture with Spring Boot and Groovy

Spring EcosystemSpring Ecosystem

In the beginning...In the beginning...

J2EE Development without EJB

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

13 of 33 10/09/14 21:54

Page 14: Micro Service Architecture with Spring Boot and Groovy

Spring DataSpring Data

DefinedDefined

the umbrella project which aims to provide a familiar andconsistent Spring-based programming model for new datastoreswhile retaining store-specific features and capabilities.

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

14 of 33 10/09/14 21:54

Page 15: Micro Service Architecture with Spring Boot and Groovy

Spring DataSpring Data

Command PatternCommand Pattern

NoSQL datastores (Mongo, Redis, Neo4J, Hadoop)Relational stores (JPA & JDBC)Umbrella Project has Sub-projects (Official & Community)Unified Interface

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

15 of 33 10/09/14 21:54

Page 16: Micro Service Architecture with Spring Boot and Groovy

Spring DataSpring Data

Spring Data for MongoDBSpring Data for MongoDB

Java Config with AbstractMongoConfigurationMongoRepository interfaceExceptions translate to DataAccessExceptionObject MappingMuch more...

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

16 of 33 10/09/14 21:54

Page 17: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

over Springover Spring

OpinionatedAutomatic configStandalone appsEmbedded containerStarter + Example buildsMetricsNo XML!Groovy!

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

17 of 33 10/09/14 21:54

Page 18: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

Configuration ComponentsConfiguration Components

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

18 of 33 10/09/14 21:54

Page 19: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

ComponentsComponents

ApplicationApplication

@EnableAutoConfiguration @ComponentScan("zim") class Application { static void main(String[] args){ new SpringApplication(Application).run(args) } }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

19 of 33 10/09/14 21:54

Page 20: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

ComponentsComponents

ConfigurationConfiguration

@Configuration class MongoConfiguration extends AbstractMongoConfiguration {

String getDatabaseName() { "invasion" }

Mongo mongo() throws Exception { new MongoClient() } }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

20 of 33 10/09/14 21:54

Page 21: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

Component Stereotypes and DomainComponent Stereotypes and Domain

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

21 of 33 10/09/14 21:54

Page 22: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

StereotypesStereotypes

ControllerController

context: /invader/zim

@Controller class InvasionController {

@Autowired QuoteRepository repository

@RequestMapping("/invader/{name}") @ResponseBody ResponseEntity quote(@PathVariable String name){ def quotes = repository.findByName(name) if(!quotes) throw new InvaderNotFoundException(name)

def quote = quotes[(int)(Math.random() * quotes.size())] new ResponseEntity(quote, OK) } }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

22 of 33 10/09/14 21:54

Page 23: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

StereotypesStereotypes

ServiceService

@Service class SomeService {

Stuff prepare(String stuffing){ //do stuff stuff } }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

23 of 33 10/09/14 21:54

Page 24: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

StereotypesStereotypes

RepositoryRepository

@Repository interface QuoteRepository extends MongoRepository<Quote, BigInteger> { List<Quote> findByName(String name) }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

24 of 33 10/09/14 21:54

Page 25: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

DomainDomain

ModelModel

@Document class Stuffing { @Id BigInteger id @Field String name @Field String description }

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

25 of 33 10/09/14 21:54

Page 26: Micro Service Architecture with Spring Boot and Groovy

Spring BootSpring Boot

BuildBuild

build.gradle

buildscript { repositories { url "http://repo.spring.io/libs-release" } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:1.1.5.RELEASE" }}apply plugin: 'spring-boot'apply plugin: 'groovy'repositories { url 'http://repo.spring.io/release'}dependencies { compile "org.codehaus.groovy:groovy:2.3.7" compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-remote-shell" compile "org.springframework.boot:spring-boot-starter-data-mongodb"}

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

26 of 33 10/09/14 21:54

Page 27: Micro Service Architecture with Spring Boot and Groovy

Invader Zim and GIRInvader Zim and GIR

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

27 of 33 10/09/14 21:54

Page 28: Micro Service Architecture with Spring Boot and Groovy

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

28 of 33 10/09/14 21:54

Page 29: Micro Service Architecture with Spring Boot and Groovy

Quote ServiceQuote Service

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

29 of 33 10/09/14 21:54

Page 30: Micro Service Architecture with Spring Boot and Groovy

DemoDemo

Invader Zim (and GIR)Invader Zim (and GIR)

Quote ServiceQuote Service

curl -s http://localhost:8080/invader/GIR

HTTP/1.1 200 OKServer: Apache-Coyote/1.1Content-Type: application/json;charset=UTF-8Transfer-Encoding: chunkedDate: Sun, 23 Mar 2014 14:17:44 GMT

{ "id":25723559900237556407223458322, "name":"GIR", "message":"Can I be a mongoose dog?"}

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

30 of 33 10/09/14 21:54

Page 31: Micro Service Architecture with Spring Boot and Groovy

ConclusionConclusionMicro Services:Micro Services:

evolved from Monolithsare smallhave single responsibilityare dispensibleare self containedhave embedded containersare self awareMUST LOOK UP INVADER ZIM!

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

31 of 33 10/09/14 21:54

Page 32: Micro Service Architecture with Spring Boot and Groovy

Thank You!!!Thank You!!!

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

32 of 33 10/09/14 21:54

Page 33: Micro Service Architecture with Spring Boot and Groovy

Q & AQ & A

Spring Boot with Groovy and Friends http://localhost/spring-boot/#/

33 of 33 10/09/14 21:54