developing microservices for paas with spring and cloud foundry

84
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Developing Microservices for PaaS with Spring and Cloud Foundry Matt Stine (@mstine) Platform Engineer, Pivotal [email protected]

Upload: spring-io

Post on 14-Jun-2015

2.772 views

Category:

Software


4 download

DESCRIPTION

Speaker: Matt Stine Developing for the Cloud Track Marc Andressen has famously said "Software is eating the world." What does that mean? We take it to mean that multiple industries with historically entrenched leaders are being disrupted by businesses built around a software core. These software factories are characterized by: tight feedback loops rapid iteration horizontal scaling mobile-first UX continuous delivery These factors have contributed to drive a change in how we approach infrastructure, which has taken the lead in adapting to meet these needs with the move to the cloud, and Platform as a Service (PaaS) offerings like Cloud Foundry have raised the level of abstraction to a focus on an ecosystem of applications and services. However, most applications are still developed as if we're living in the previous generation of both business and infrastructure: the monolithic application. Microservices - small, loosely coupled applications that follow the Unix philosophy of ""doing one thing well"" - represent the application development side of enabling rapid, iterative development, horizontal scale, polyglot clients, and continuous delivery. They also enable us to scale application development and eliminate long term commitments to a single technology stack. While microservices are simple, they are certainly not easy. It's recently been said that "microservices are not a free lunch." Interestingly enough, if you look at the concerns typically expressed about microservices, you'll find that they are exactly the challenges that a PaaS is intended to address. So while microservices do not necessarily imply cloud (and vice versa), there is in fact a symbiotic relationship between the two, with each approach somehow compensating for the limitations of the other, much like the practices of eXtreme Programming do the same. This session will describe architectural patterns for developing microservices: Service Decomposition API Gateways Stateless / Shared-Nothing Apps Configuration and Backing Service Consumption Fault Tolerance Along the way we'll see how to leverage technologies such as Spring Boot and Reactor to develop microservices targeted at Cloud Foundry.

TRANSCRIPT

Page 1: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Developing Microservices for PaaS with Spring and Cloud Foundry

Matt Stine (@mstine) Platform Engineer, Pivotal

[email protected]

Page 2: Developing Microservices for PaaS with Spring and Cloud Foundry

Architecting for Continuous Delivery

2

$Busin

ess

Devel

opm

ent

QA

Ope

ratio

nsCu

stom

er

Page 3: Developing Microservices for PaaS with Spring and Cloud Foundry

Architecting for Continuous Delivery

3

$

Page 4: Developing Microservices for PaaS with Spring and Cloud Foundry

Continuous Delivery - How?

4

Page 5: Developing Microservices for PaaS with Spring and Cloud Foundry

Warner Music: Software Factories

Warner Software Factory Platform • New applications and major updates

- Before: 6 months, team of 10 developers - After: 6 weeks, same team - Speed/Agility: 400% faster on new platform - HR Hard Savings: $1.1M per application

update delivered

5

Page 6: Developing Microservices for PaaS with Spring and Cloud Foundry

Iterative Development

6

Design Develop

Test

Customer Feedback Customer

Delivery

Analytics

Page 7: Developing Microservices for PaaS with Spring and Cloud Foundry

Horizontal Scale

7

Slow/Expensive Fast/Cheap

Page 8: Developing Microservices for PaaS with Spring and Cloud Foundry

Diversity of Clients

8

http://money.cnn.com/2014/02/28/technology/mobile/mobile-apps-internet/

In January 2014, mobile devices accounted for 55% of Internet usage in the United States. Apps made up 47% of Internet traffic and 8% of traffic came from mobile

browsers.

Page 9: Developing Microservices for PaaS with Spring and Cloud Foundry

9

Software Factories

Feedback Rapid Iteration

Horizontal Scale

Diversity of Clients

Continuous Delivery

InfrastructureApplications

MonolithsMicroservices

Physical/Virtual

Cloud Foundry

Page 10: Developing Microservices for PaaS with Spring and Cloud Foundry

New Architectural Constraints

• Cloud Foundry optimizes for 12 Factor Linux applications • Microservices: a radical departure from traditional monolithic

applications • In both cases, the enterprise is

forced to “think different.”

10

Page 11: Developing Microservices for PaaS with Spring and Cloud Foundry

How XP Practices Support Each Other

11http://www.kusmin.eu/wiki/index.php/How_XP_Practices_Support_Each_Other

Page 12: Developing Microservices for PaaS with Spring and Cloud Foundry

A Symbiotic Relationship…

12

MicroservicesCloud Foundry

Page 13: Developing Microservices for PaaS with Spring and Cloud Foundry

Patterns

• Microservice • API Gateway • Stateless/Shared-Nothing • Configuration/Service Consumption • Fault Tolerance

13

Page 14: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Pattern: Microservice

Page 15: Developing Microservices for PaaS with Spring and Cloud Foundry

Monolithic Architecture

15

Relational Database

Data Access

Service

HTML JavaScript MVC

Service

Monolithic ApplicationBrowser

Page 16: Developing Microservices for PaaS with Spring and Cloud Foundry

Monolithic Architectures

• Complex / Easy • Modularity Dependent Upon Language / Frameworks • Change Cycles Tightly Coupled / Obstacle to Frequent Deploys • Inefficient Scaling • Can Be Intimidating to New Developers • Obstacle to Scaling Development • Requires Long-Term Commitment to Technical Stack

16

Page 17: Developing Microservices for PaaS with Spring and Cloud Foundry

Microservice Architecture

17

…HTTP

HTTP

HTTP

HTTP

HTTP

HTTP

AMQPAMQP

Relational DB

Key/Value Store

Graph DB

Page 18: Developing Microservices for PaaS with Spring and Cloud Foundry

Microservice Architectures

• Simple / Challenging • Modularity Based on Component Services • Change Cycles Decoupled / Enable Frequent Deploys • Efficient Scaling • Individual Components Less Intimidating to New Developers • Enables Scaling of Development • Eliminates Long-Term Commitment to Technical Stack

18

Page 19: Developing Microservices for PaaS with Spring and Cloud Foundry

Conway’s Law

19

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

Melvyn Conway, 1967

Page 20: Developing Microservices for PaaS with Spring and Cloud Foundry

Organize Around Business Capabilities

20

Data Access

Service

HTML JavaScript MVC

Service

UI S

pecialists

Middlew

are S

pecialists

DB

As

Business C

apability

Business C

apability

Business C

apabilitySiloed Functional Teams

http://martinfowler.com/articles/microservices.html#OrganizedAroundBusinessCapabilities

Siloed Application Architectures

Cross- functional Teams

Microservice Architectures

Page 21: Developing Microservices for PaaS with Spring and Cloud Foundry

Partitioning Strategies

• By Noun (e.g. product info service) • By Verb (e.g. shipping service) • Single Responsibility Principle

(http://programmer.97things.oreilly.com/wiki/index.php/The_Single_Responsibility_Principle)

• Bounded Context (http://martinfowler.com/bliki/BoundedContext.html)

21

Page 22: Developing Microservices for PaaS with Spring and Cloud Foundry

UNIX Pipes and Filters

22cut -d" " -f1 < access.log | sort | uniq -c | sort -rn | less

Page 23: Developing Microservices for PaaS with Spring and Cloud Foundry

Choreography over Orchestration

23

https://www.flickr.com/photos/gabrielsaldana/5896491978

https://www.flickr.com/photos/chrisbrenschmidt/2223763842

Page 24: Developing Microservices for PaaS with Spring and Cloud Foundry

Challenges of Microservices

• Distributed System • Remote Calls More Expensive Than In-process Calls • Eventual Consistency • Features Spanning Multiple Services • Dependency Management / API Versioning • Refactoring Module Boundaries

24

Page 25: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Pattern: API Gateway

Page 26: Developing Microservices for PaaS with Spring and Cloud Foundry

26

How many microservices?ELEVEN

Page 27: Developing Microservices for PaaS with Spring and Cloud Foundry

Direct Connect

27

Chatty API

Web

Unfriendly

Protocols

Page 28: Developing Microservices for PaaS with Spring and Cloud Foundry

API Gateway

28

API

Gat

eway

…Client

Specific

APIs

Single

Entry

Point

Protocol

Translation

Page 29: Developing Microservices for PaaS with Spring and Cloud Foundry

Netflix API Gateway

29

Page 30: Developing Microservices for PaaS with Spring and Cloud Foundry

The Need for Concurrency

30

Product Details API

Product Info

Recommendations

Reviews

Call Concurrently!

Page 31: Developing Microservices for PaaS with Spring and Cloud Foundry

Building API Gateways

• Reactor (https://spring.io/blog/2013/11/12/it-can-t-just-be-big-data-it-has-to-be-fast-data-reactor-1-0-goes-ga)

• RxJava (https://github.com/Netflix/RxJava) • Vert.x (http://vertx.io/) • Go (http://golang.org/) • Node.js (http://nodejs.org/) • Pivotal CF Mobile Services (https://network.pivotal.io/products/

p-api-gateway)

31

Page 32: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Pattern: Stateless/Shared-Nothing

!

Page 33: Developing Microservices for PaaS with Spring and Cloud Foundry

Elasticity

33

http://www.flickr.com/photos/karen_d/2944127077

Page 34: Developing Microservices for PaaS with Spring and Cloud Foundry

Ephemerality

34

http://www.flickr.com/photos/smathur/852322080

http://www.flickr.com/photos/smathur/852322080

Page 35: Developing Microservices for PaaS with Spring and Cloud Foundry

Why is state a problem?

35

Router

DEA DEA

Page 36: Developing Microservices for PaaS with Spring and Cloud Foundry

Why is state a problem?

36

Router

DEA DEA

X

X But my state was in

there!

Page 37: Developing Microservices for PaaS with Spring and Cloud Foundry

The Usual Suspects

37

6’6”

6’0”

5’6”

5’0”

4’6”

4’0”

Page 38: Developing Microservices for PaaS with Spring and Cloud Foundry

Option #1: Push State to the Client

38

Cookies, HTML 5, Single Page Applications (SPA)

Page 39: Developing Microservices for PaaS with Spring and Cloud Foundry

Option #2: External Services

39

Router

Redis Session Manager

DEA DEA

Page 40: Developing Microservices for PaaS with Spring and Cloud Foundry

Option #2: External Services

• Redis • Create a CF service containing a name, label, or tag with

“session-replication” as a substring. • https://github.com/cloudfoundry/java-buildpack/blob/master/

docs/container-tomcat.md#session-replication • Gemfire HTTP Session Management

• http://gopivotal.com/products/pivotal-tc-server

40

Page 41: Developing Microservices for PaaS with Spring and Cloud Foundry

There is no file system…

41

Page 42: Developing Microservices for PaaS with Spring and Cloud Foundry

It’s not shared…

42

Router

DEA

HTTP POST - 200 OK

DEA

Page 43: Developing Microservices for PaaS with Spring and Cloud Foundry

It’s not shared…

43

Router

DEA

HTTP GET - 404 NOT FOUND

DEAX

X

Page 44: Developing Microservices for PaaS with Spring and Cloud Foundry

It’s not persistent…

44

Router

DEA

HTTP POST - 200 OK

DEA

Page 45: Developing Microservices for PaaS with Spring and Cloud Foundry

It’s not persistent…

45

Router

DEA DEA

X

X

Page 46: Developing Microservices for PaaS with Spring and Cloud Foundry

It’s not persistent…

46

Router

DEA DEA

HTTP GET - 404 NOT FOUND X

X

Page 47: Developing Microservices for PaaS with Spring and Cloud Foundry

Use a persistent store!

• Amazon S3 (http://aws.amazon.com/s3) • Google Cloud Storage (https://cloud.google.com/products/cloud-

storage) • EMC Atmos (http://www.emc.com/storage/atmos/atmos.htm) • OpenStack Swift (http://swift.openstack.org) • Hadoop HDFS (http://www.gopivotal.com/big-data/pivotal-hd) • Riak CS for Pivotal CF (https://network.pivotal.io/products/p-

riakcs)

47

Page 48: Developing Microservices for PaaS with Spring and Cloud Foundry

48

https://github.com/cloudfoundry-samples/cf-s3-demo

Page 49: Developing Microservices for PaaS with Spring and Cloud Foundry

49

@Configuration @Profile("cloud") public class CloudConfig extends AbstractCloudConfig { ! @Bean public DataSource dataSource() { // Default pool size to 4 connections to support ClearDB Spark (free) PooledServiceConnectorConfig.PoolConfig poolConfig = new PooledServiceConnectorConfig.PoolConfig(4, 200); ! DataSourceConfig config = new DataSourceConfig(poolConfig, new DataSourceConfig. ConnectionConfig("")); ! return connectionFactory().dataSource(config); } ! @Bean public S3 s3() { return connectionFactory().service(S3.class); } !}

Page 50: Developing Microservices for PaaS with Spring and Cloud Foundry

50

public class S3 { ! private AmazonS3 amazonS3; private String bucket; ! public S3(AmazonS3 amazonS3, String bucket) { this.amazonS3 = amazonS3; this.bucket = bucket; } ! public S3File createS3FileObject(String id, String name, File file) { return new S3File(id, bucket, name, file); } ! public void put(S3File file) { PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, file.getActualFileName(), file.getFile()); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); amazonS3.putObject(putObjectRequest); } ! public void delete(S3File file) { amazonS3.deleteObject(bucket, file.getActualFileName()); } !}

Page 51: Developing Microservices for PaaS with Spring and Cloud Foundry

51

@RequestMapping(value = "/upload", method = RequestMethod.POST) public String handleFileUpload(@RequestParam("file") MultipartFile file) { ! String id = UUID.randomUUID().toString(); File uploadedFile = new File(file.getOriginalFilename()); ! try { byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(uploadedFile) ); stream.write(bytes); stream.close(); } catch (IOException e) { throw new RuntimeException("Failed to upload file!", e); } ! S3File s3File = s3.createS3FileObject(id, file.getOriginalFilename(), uploadedFile); ! s3.put(s3File); log.info(s3File.getName() + " put to S3."); repository.save(s3File); log.info(s3File.getName() + " record saved to MySQL."); uploadedFile.delete(); log.info(s3File.getFile().getAbsolutePath() + " is deleted."); ! return “redirect:/"; }

Page 52: Developing Microservices for PaaS with Spring and Cloud Foundry

52

@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) public String deleteFile(@PathVariable String id) { ! S3File s3File = repository.findOne(id); ! repository.delete(s3File); log.info(s3File.getId() + " deleted from MySQL."); s3.delete(s3File); log.info(s3File.getActualFileName() + " deleted from S3 bucket."); ! return "redirect:/"; }

Page 53: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Pattern: Configuration/Service Consumption

Page 54: Developing Microservices for PaaS with Spring and Cloud Foundry

54

http://12factor.net/

Page 55: Developing Microservices for PaaS with Spring and Cloud Foundry

What is configuration?

• Resource handles to databases and other backing services • Credentials to external sources (e.g. S3, Twitter, ...) • Per-deploy values (e.g. canonical hostname for deploy) • ANYTHING that’s likely to vary between deploys (dev, test, stage,

prod)

55

Page 56: Developing Microservices for PaaS with Spring and Cloud Foundry

Where NOT to store it:

• In the CODE (Obvious) • In PROPERTIES FILES (That’s code...) • In the BUILD (ONE build, MANY deploys) • In the APP SERVER (e.g. JNDI datasources)

56

Page 57: Developing Microservices for PaaS with Spring and Cloud Foundry

Store it in the ENVIRONMENT!

57

Page 58: Developing Microservices for PaaS with Spring and Cloud Foundry

58

TMPDIR=/home/vcap/tmp!VCAP_APP_PORT=61863!USER=vcap!VCAP_APPLICATION={"instance_id":"b3e92a6fc443436888a525d100c91a12",! "instance_index":0,"host":"0.0.0.0","port":61863,"started_at":! "2013-12-04 01:52:01 +0000","started_at_timestamp":1386121921,! "start":"2013-12-04 01:52:01+0000","state_timestamp":1386121921,! "limits":{"mem":512,"disk":1024,"fds":16384},! "application_version":"09c9bfe9-c14e-4fcb-8ad8-9fcd4b854893",! "application_name":"cf-s3-demo","application_uris":["cf-s3-demo.! cfapps.io"],"version":"09c9bfe9-c14e-4fcb-8ad8-9fcd4b854893",! "name":"cf-s3-demo","uris":["cf-s3-demo.cfapps.io"],"users":! null}!PATH=/bin:/usr/bin!PWD=/home/vcap!VCAP_SERVICES={"mongolab-n/a":[{"name":"mongo-cf-s3","label":"mongolab-n/a",! "tags":["mongodb","document"],"plan":"sandbox","credentials":{! "uri":"mongodb://user:****@ds053708.mongolab.com:! 53708/CloudFoundry_shageik2_iijfo9ve"}}],"user-provided":[{"name":! "s3-bucket-service","label":"user-provided","tags":[],! "credentials":{"awsAccessKey":"**********","awsSecretKey":! "**********","bucket":"cf-s3-demo"},"syslog_drain_url":""}]}!SHLVL=1!HOME=/home/vcap/app!PORT=61863!VCAP_APP_HOST=0.0.0.0!DATABASE_URL=!MEMORY_LIMIT=512m!_=/usr/bin/env

Cloud Foundry Environment

Page 59: Developing Microservices for PaaS with Spring and Cloud Foundry

When am I done?

59

When “...the codebase could be made open source at any moment, without compromising any credentials.”

http://12factor.net/config

Page 60: Developing Microservices for PaaS with Spring and Cloud Foundry

Why environment variables?

• Easy to change • Little chance of being “checked in” to VCS • Language/OS-agnostic standard

60

Page 61: Developing Microservices for PaaS with Spring and Cloud Foundry

Backing Services

61

Application

Relational DB

SMTP Server Object Store

Twitter

Page 62: Developing Microservices for PaaS with Spring and Cloud Foundry

62

TMPDIR=/home/vcap/tmp!VCAP_APP_PORT=61863!USER=vcap!VCAP_APPLICATION={"instance_id":"b3e92a6fc443436888a525d100c91a12",! "instance_index":0,"host":"0.0.0.0","port":61863,"started_at":! "2013-12-04 01:52:01 +0000","started_at_timestamp":1386121921,! "start":"2013-12-04 01:52:01+0000","state_timestamp":1386121921,! "limits":{"mem":512,"disk":1024,"fds":16384},! "application_version":"09c9bfe9-c14e-4fcb-8ad8-9fcd4b854893",! "application_name":"cf-s3-demo","application_uris":["cf-s3-demo.! cfapps.io"],"version":"09c9bfe9-c14e-4fcb-8ad8-9fcd4b854893",! "name":"cf-s3-demo","uris":["cf-s3-demo.cfapps.io"],"users":! null}!PATH=/bin:/usr/bin!PWD=/home/vcap!VCAP_SERVICES={"mongolab-n/a":[{"name":"mongo-cf-s3","label":"mongolab-n/a",! "tags":["mongodb","document"],"plan":"sandbox","credentials":{! "uri":"mongodb://user:****@ds053708.mongolab.com:! 53708/CloudFoundry_shageik2_iijfo9ve"}}],"user-provided":[{"name":! "s3-bucket-service","label":"user-provided","tags":[],! "credentials":{"awsAccessKey":"**********","awsSecretKey":! "**********","bucket":"cf-s3-demo"},"syslog_drain_url":""}]}!SHLVL=1!HOME=/home/vcap/app!PORT=61863!VCAP_APP_HOST=0.0.0.0!DATABASE_URL=!MEMORY_LIMIT=512m!_=/usr/bin/env

Cloud Foundry Environment

Page 63: Developing Microservices for PaaS with Spring and Cloud Foundry

63

https://github.com/spring-projects/spring-cloud

Page 64: Developing Microservices for PaaS with Spring and Cloud Foundry

64

Cloud Foundry Connector

Heroku Connector

Core

Spring Service Connector

Spring Cloud Modules

Page 65: Developing Microservices for PaaS with Spring and Cloud Foundry

Spring Service Beans

65

public class CloudConfig extends AbstractCloudConfig {! @Bean! public ConnectionFactory rabbitConnectionFactory() {! return connectionFactory.rabbitConnectionFactory();! }!! @Bean! public DataSource dataSource() {! return connectionFactory().dataSource();! }!! @Bean! public S3 s3() {! return connectionFactory().service(S3.class);! }!}

Page 66: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Pattern: Fault Tolerance

Page 67: Developing Microservices for PaaS with Spring and Cloud Foundry

Fault Tolerance at Netflix

67http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 68: Developing Microservices for PaaS with Spring and Cloud Foundry

68

Without taking steps to ensure fault tolerance, 30 dependencies each with 99.99% uptime would result in 2+ hours downtime/month (99.99%30 = 99.7% uptime = 2+ hours downtime in a month).

http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html

Page 69: Developing Microservices for PaaS with Spring and Cloud Foundry

Circuit Breaker

69

Page 70: Developing Microservices for PaaS with Spring and Cloud Foundry

Circuit Breaker State Machine

70

Closed on call / pass through call succeeds / reset count call fails / count failure threshold reached / trip breaker

Open on call / fail on timeout / attempt reset

Half-Open on call / pass through call succeeds / reset call fails / trip breaker

trip breaker

trip breaker

attempt reset

reset

Page 71: Developing Microservices for PaaS with Spring and Cloud Foundry

71

https://github.com/Netflix/Hystrix

Page 72: Developing Microservices for PaaS with Spring and Cloud Foundry

Hystrix

• Latency and Fault Tolerance • Realtime Operations • Concurrency

72

Page 73: Developing Microservices for PaaS with Spring and Cloud Foundry

Hello Hystrix!

73

public class CommandHelloWorld extends HystrixCommand<String> {!! private final String name;!! public CommandHelloWorld(String name) {! super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));! this.name = name;! }!! @Override! protected String run() {! return "Hello " + name + "!";! }!}

Page 74: Developing Microservices for PaaS with Spring and Cloud Foundry

Consuming Hystrix Commands

74

String s = new CommandHelloWorld(“Bob").execute();!!Future<String> s = new CommandHelloWorld(“Bob").queue();!!Observable<String> s = new CommandHelloWorld(“Bob").observe();!!s.subscribe(new Action1<String>() {!! @Override! public void call(String s) {! // value emitted here! }!!});

Page 75: Developing Microservices for PaaS with Spring and Cloud Foundry

Fail Fast

75

public class CommandThatFailsFast extends HystrixCommand<String> {!! private final boolean throwException;!! public CommandThatFailsFast(boolean throwException) {! super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));! this.throwException = throwException;! }!! @Override! protected String run() {! if (throwException) {! throw new RuntimeException("failure from CommandThatFailsFast");! } else {! return "success";! }! }

Page 76: Developing Microservices for PaaS with Spring and Cloud Foundry

Fail Silent

76

public class CommandThatFailsSilently extends HystrixCommand<String> {!! private final boolean throwException;!! public CommandThatFailsSilently(boolean throwException) {! super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));! this.throwException = throwException;! }!! @Override! protected String run() {! if (throwException) {! throw new RuntimeException("failure from CommandThatFailsFast");! } else {! return "success";! }! }!! @Override! protected String getFallback() {! return null;! }!}

Page 77: Developing Microservices for PaaS with Spring and Cloud Foundry

Static Fallback

77

@Override!protected Boolean getFallback() {!! return true;!}

Page 78: Developing Microservices for PaaS with Spring and Cloud Foundry

Stubbed Fallback

78

@Override!protected UserAccount run() {! // fetch UserAccount from remote service! // return UserAccountClient.getAccount(customerId);! throw new RuntimeException("forcing failure for example");!}!!@Override!protected UserAccount getFallback() {! /**! * Return stubbed fallback with some static defaults, placeholders,! * and an injected value 'countryCodeFromGeoLookup' that we'll use! * instead of what we would have retrieved from the remote service.! */! return new UserAccount(customerId, "Unknown Name",! countryCodeFromGeoLookup, true, true, false);!}

Page 79: Developing Microservices for PaaS with Spring and Cloud Foundry

Fallback: Cache via Network

79

Page 80: Developing Microservices for PaaS with Spring and Cloud Foundry

Primary + Secondary with Fallback

80

Page 81: Developing Microservices for PaaS with Spring and Cloud Foundry

Hystrix Dashboard

81

Page 82: Developing Microservices for PaaS with Spring and Cloud Foundry

A Failing Circuit

82

Page 83: Developing Microservices for PaaS with Spring and Cloud Foundry

© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Developing Microservices for PaaS with Spring and Cloud Foundry

Microservice API Gateway Stateless/ Shared-Nothing

!

Configuration/ Service Consumption

Fault Tolerance

Page 84: Developing Microservices for PaaS with Spring and Cloud Foundry

Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 84

Thank You!

Matt Stine (@mstine) [email protected]

http://mattstine.com

@springcentral | spring.io/video

Apps + Data + Cloud: What Does It All Mean?

(a.k.a. “Microservices Part 2) NEXT IN DALLAS BALLROOM G!