spring cloud jug switzerland

50
AGIM EMRULI, ALAIN SAHLI MICROSERVICES MIT SPRING CLOUD

Upload: agim-emruli

Post on 07-Aug-2015

189 views

Category:

Software


5 download

TRANSCRIPT

Page 1: Spring Cloud JUG Switzerland

AGIM EMRULI, ALAIN SAHLIMICROSERVICES MIT SPRING CLOUD

Page 2: Spring Cloud JUG Switzerland

AGIM EMRULI

AGIM.EMRULI@ MIMACOM.COM

ALAIN SAHLI

ALAIN.SAHLI@ MIMACOM.COM

Page 3: Spring Cloud JUG Switzerland

CLOUD

SERVICE REGISTRY,CIRCUIT BREAKER, METRICS

CORE

FRAMEWORK SECURITY GROOVY REACTOR

IO E

XECU

TION

IO F

OUND

ATIO

NGRAILS

FULL STACK, WEB

XD

STREAMS, TAPS, JOBS

BOOT

BOOTABLE, MINIMAL, OPS-READY

BATCH

JOBS, STEPS,READERS, WRITERS

DATA

RELATIONAL DATA NON-RELATIONAL DATA

BIG DATA

INGESTION, EXPORT,ORCHESTRATION, HADOOP

WEB

CONTROLLERS, REST, WEBSOCKET

INTEGRATION

CHANNELS, FILTERS,ADAPTERS, TRANSFORMERS

IO C

OORD

INAT

ION

Page 4: Spring Cloud JUG Switzerland

TOOLBOXFOR DISTRIBUTED SYSTEMS

Page 5: Spring Cloud JUG Switzerland

DISTRIBUTED SYSTEM DEPLOYMENTS@GITHUB

175 DEPLOYMENTS / DAY

Page 6: Spring Cloud JUG Switzerland

NETFLIXSERVICE ORIENTED ARCHITECTURE

Page 7: Spring Cloud JUG Switzerland

SPRING CLOUDINTRODUCTION

Spring Cloud

BusConfig Netflix

AWS

Cloud FoundryCLIConnectors

Starters

Page 8: Spring Cloud JUG Switzerland

Application

CONFIGURATION MANAGEMENTMONOLITHIC VS. DISTRIBUTED

Application

JNDI

Service

ServiceService

Service

Service

Page 9: Spring Cloud JUG Switzerland

Spring Cloud Config

Spring Cloud Config Server

GIT

SVN

File

Page 10: Spring Cloud JUG Switzerland

Config Server

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

Page 11: Spring Cloud JUG Switzerland

Spring Cloud Config Server

Application

Spring Cloud Config Client

Application

Spring Cloud Config Client

Application

Spring Cloud Config Client

Page 12: Spring Cloud JUG Switzerland

Application

Spring Cloud Config Client

@SpringBootApplicationpublic class CustomerApp { public static void main(String[] args) { SpringApplication.run(CustomerApp.class, args); } }

Bootstrap

Page 13: Spring Cloud JUG Switzerland

Spring Cloud Bus

Spring Cloud Config Server

Application

Application

/bus/refresh

AMQP

Page 14: Spring Cloud JUG Switzerland
Page 15: Spring Cloud JUG Switzerland
Page 16: Spring Cloud JUG Switzerland
Page 17: Spring Cloud JUG Switzerland
Page 18: Spring Cloud JUG Switzerland

PATTERNSSTABILITY CAPACITY TRANSPARENCY

Page 19: Spring Cloud JUG Switzerland

SPRING CLOUDNETFLIX

Hystrix

Feign

Zuul

Eureka

Turbine

Ribbon

Service Registry

Circuit Breaker

Stream Aggregator

Load Balancer

Edge Service

HTTP Communication

Page 20: Spring Cloud JUG Switzerland

HYSTRIXCIRCUIT BREAKER

Execute Command

QueuePool

available

Run

Fallback

Page 21: Spring Cloud JUG Switzerland

HYSTRIXBULKHEADS

Tomcat Thread Pool

Th

read

- 1

Service

Service

Service Service

Th

read

- 2

Th

read

- 3

XT

hre

ad -

4

Th

read

- 5

Th

read

- 6

Th

read

- 7

Th

read

- 8

Page 22: Spring Cloud JUG Switzerland

HYSTRIXBULKHEADS

Execute Command

QueuePool

available

Execute Command

QueuePool

available

Execute Command

QueuePool

available

Page 23: Spring Cloud JUG Switzerland

HYSTRIX EXAMPLESERVICE CONSUMER

public class SearchGateway { @HystrixCommand(fallbackMethod = "fallback") public List<SearchHit> search(String query) { return …; } public List<SearchHit> fallback() { return Collections.emptyList(); } }

Page 24: Spring Cloud JUG Switzerland

HYSTRIXTRANSPARENCY

Page 25: Spring Cloud JUG Switzerland

HYSTRIX DASHBOARDEXAMPLE

@EnableCircuitBreaker@EnableHystrixDashboardpublic class HystrixApp { public static void main(String[] args) { SpringApplication.run(HystrixApp.class, args); }}

Page 26: Spring Cloud JUG Switzerland

TURBINEAGGREGATOR

Dashboard

Service

Service

Dashboard

Turbine

Service Service

Page 27: Spring Cloud JUG Switzerland

EUREKASERVICE DISCOVERY

Service

Service

Service

Service

XService

Service

Service

Service

Eu

reka

Page 28: Spring Cloud JUG Switzerland

EUREKA REGISTRATIONEXAMPLE

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

spring.application.name=customers

Page 29: Spring Cloud JUG Switzerland

EUREKA REGISTRATIONEXAMPLE

Discovery Client

Application

HostPortURI

Page 30: Spring Cloud JUG Switzerland

RIBBONLOAD-BALANCER

Service

Service

Eu

reka

Service

Service

Eu

reka

ServiceService

Load Balancer

Page 31: Spring Cloud JUG Switzerland

RIBBONRESTTEMPLATE INTEGRATION

@Servicepublic class Service { @Autowired @LoadBalanced RestTemplate restTemplate; public String callService() { return restTemplate.getForObject("http://CUSTOMERS/{id}", String.class,"23"); }}

Page 32: Spring Cloud JUG Switzerland

ZUULEDGE-SERVICE

Service

Eu

reka

Edge Proxy

Service

Eu

reka

ServiceService

Load Balancer

Web Browser

Web Browser

Page 33: Spring Cloud JUG Switzerland

ZUULREVERSE PROXY SETUP

@EnableAutoConfiguration@EnableZuulProxypublic class SimpleZuulServerApplication { public static void main(String[] args) { SpringApplication.run(SampleZuulProxyApplication.class, args); } }

http://localhost:9090/customers http://localhost:9090/stores

Page 34: Spring Cloud JUG Switzerland

Web ServerLoad Balancer

Service Discovery

EurekaCustomers Stores

Config Server

Circuit Breaker Dashboard

Browser

Page 35: Spring Cloud JUG Switzerland
Page 36: Spring Cloud JUG Switzerland

SPRING CLOUDAMAZON WEBSERVICES

Page 37: Spring Cloud JUG Switzerland

Instance Meta-data@Componentpublic class ApplicationInfoBean { @Value("${ami-id}") private String amiId; @Value("${hostname}") private String hostname; @Value("${instance-type}") private String instanceType; @Value("${services/domain}") private String serviceDomain; }

Page 38: Spring Cloud JUG Switzerland

Amazon RDS

Schema Design

Query construction / tuning

Availability

Backup & Recovery

Patch Management

Storage Upgrades

Page 39: Spring Cloud JUG Switzerland

Amazon RDS

@EnableRdsInstance( dbInstanceIdentifier = “test", password = “secret", readReplicaSupport = true) public static class AppConfig {}

Page 40: Spring Cloud JUG Switzerland

RDS Instance Support@Servicepublic class JdbcPersonService implements PersonService { private final JdbcTemplate jdbcTemplate; @Autowired public JdbcPersonService(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } @Override @Transactional(readOnly = true) public List<Person> all() { return this.jdbcTemplate.query("SELECT * FROM Person”, … ); } @Override @Transactional public void store(Person person) { this.jdbcTemplate.update("INSERT INTO Person …”); }}

Page 41: Spring Cloud JUG Switzerland

Amazon SQS

HTTP Messaging

Only String payload

No Transactions

Visibility Rules

Page 42: Spring Cloud JUG Switzerland

Message Listeners

@Componentpublic class SqsController { @MessageMapping("myQueue") @SendTo("replyQueue") private String receiveMessage(MessageToProcess message, @Header(“ApproximateFirstReceiveTimestamp”) String timeStamp) { return "someReply"; }}

Page 43: Spring Cloud JUG Switzerland

Application Instance

Application Instance

Application Instance

Page 44: Spring Cloud JUG Switzerland

SNS Controllers@RestController@RequestMapping("/sns/receive") public class SnsEndpointController { @NotificationSubscriptionMapping public void confirmSubscription( NotificationStatus notificationStatus) { notificationStatus.confirmSubscription(); } @NotificationMessageMapping public void receiveNotification( @NotificationMessage String message, @NotificationSubject String subject) { }}

Page 45: Spring Cloud JUG Switzerland

Elasticache

Application Instance

Application Instance

Application Instance

Application Instance

Page 46: Spring Cloud JUG Switzerland

Caching Service

@Servicepublic class ExpensiveService { @Cacheable("CacheCluster") public String calculateExpensiveValue(String key){ return …; }}

Page 47: Spring Cloud JUG Switzerland
Page 48: Spring Cloud JUG Switzerland

{ "Resources": { "ec2instance": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId": "ami-6a56b81d", "InstanceType": "m1.small", } }, "database": { "Type": "AWS::RDS::DBInstance", "Properties": { "AllocatedStorage": "5", "DBInstanceClass": "db.m1.small", "DBName": "test", } } }

Page 49: Spring Cloud JUG Switzerland
Page 50: Spring Cloud JUG Switzerland

FRAGEN?