+ All Categories
Home > Technology > Spring Cloud on AWS

Spring Cloud on AWS

Date post: 23-Jan-2018
Category:
Upload: spring-by-pivotal
View: 2,354 times
Download: 0 times
Share this document with a friend
36
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud on AWS Agim Emruli @aemruli
Transcript
Page 1: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud on AWSAgim Emruli

@aemruli

Page 2: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud for AWS - History

2

1.01.0 M2 Angel Brixton Camden

ElasticSpring

1.0 M1

Page 3: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Amazon Web Services

3

Core Cloud Services

Rich Platform Services

Developer Productivity

Compute Database Storage Networking

AnalyticsEnterprise Apps

Mobile Services

Internet of Things

Developer Tools

Manage- ment

Security Identity

Application Services

Page 4: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud for AWS

4

Compute Database Storage Networking

AnalyticsEnterprise Apps

Mobile Services

Internet of Things

Developer Tools

Manage- ment

Security Identity

Application Services

Core Cloud Services

Rich Platform Services

Developer Productivity

Page 5: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Triangle

5

Simple ObjectD

epen

denc

y In

ject

ion Aspect-oriented D

ev

Portable Service Abstractions

Page 6: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Dependency Injection with Environment

6

@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; }

Meta-Data

Tags

User Meta-data

Page 7: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Dependency Injection with Services

7

@EnableRdsInstance( dbInstanceIdentifier = “test”, password = “${user.password}“, readReplicaSupport = true) public static class AppConfig {}

Page 8: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Amazon RDS Read-Replicas

8

Application

DataSource

Page 9: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Amazon RDS Read-Replicas

9

Application

DataSource

Page 10: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Read-replica Demarcation

10

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

Page 11: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Triangle

11

Simple ObjectD

epen

denc

y In

ject

ion Aspect-oriented D

ev

Portable Service Abstractions

Page 12: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Simple Storage - Resource Loader Abstractionpublic class S3LoadingClass { @Autowired private ResourceLoader rl; public void download() { Resource resource = rl.getResource("s3://myBucket/myFile.txt"); resource.getInputStream(); } public void upload(){ WritableResource writableResource = (WritableResource) rl.getResource("s3://myBucket/newFile.txt"); writableResource.getOutputStream(); } }

12

Page 13: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Simple E-Mail Service - Mail Senderpublic class MailSender { @Autowired private MailSender mailSender; @Test public void sendMail() throws Exception { SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setFrom(“[email protected]”); simpleMailMessage.setTo(“[email protected]”); simpleMailMessage.setSubject("test subject"); simpleMailMessage.setText("test content"); this.mailSender.send(simpleMailMessage); } }

13

Page 14: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Elasticache - Caching

14

Application

Cache Manager

Application

Cache Manager

Redis

Memcached

Page 15: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Caching Service Abstraction

@Service @EnableElastiCache( @CacheClusterConfig(name = “myCache”))public class ExpensiveService { @Cacheable("myCache") public String calculateExpensiveValue(String key){ return …; }}

15

Page 16: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Amazon Simple Queueing Service

• HTTP-based messaging service

• Only String payloads

• Pay-per message (millions)

• No transactions

• Visibility rules

16

Page 17: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Sending Messages with Spring Messaging@Service@EnableSqspublic class MessageSendingBean { private final QueueMessagingTemplate messagingTemplate; @Autowired public MessageSendingBean(AmazonSQS amazonSqs) { this.messagingTemplate = new QueueMessagingTemplate(amazonSqs); } public String sendAndReceive(String payload) { this.messagingTemplate.convertAndSend("requestQueue", payload); return this.messagingTemplate.

receiveAndConvert("resultQueue", String.class); } }

17

Page 18: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Polling Message Using Container

@Component@EnableSqspublic class MessageReceivingBean { @SqsListener("receivingQueue") public @SendTo("responseQueue") Confirmation processEvent(CustomEvent customEvent){ return new Confirmation(); } }

18

Page 19: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Acknowledgment@Component@EnableSqspublic class MessageReceivingBean { @SqsListener(value = "receivingQueue", deletionPolicy = NEVER) public @SendTo("responseQueue") Confirmation processEvent( CustomEvent customEvent, Acknowledgment acknowledgment){ if(successful){ acknowledgment.acknowledge(); } return new Confirmation(); } }

19

Page 20: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Combining AWS Services

20

Amazon Elastic Transcoder

Amazon CloudWatch

Amazon S3Application

Listener

Page 21: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

HTTP-based Notifications with Amazon SNS

21

Amazon SNSApplication

ControllerSubscribeConfirm

EventDelete

Page 22: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring MVC - SNS Controller@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) { }}

22

Page 23: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Deployment using Cloud Formation

23

Template Cloud Formation Application

Page 24: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Cloud Formation Auto Configuration

24

Application

spring-cloud-aws-autoconfigure

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-aws-autoconfigure</artifactId> </dependency>

Page 25: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Auto Config Services@Servicepublic class ApplicationBean { @Autowired private DataSource dataSource; @Autowired private MailSender mailSender; @Cacheable("myCache") public void cache(){ } @SqsListener("myQueue") public void receiveMessage(){ } }

25

Page 26: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Pushing Metrics with Spring Boot Actuator

@Servicepublic class MetricProducer { @Autowired private CounterService counterService; public void sendOrder() { this.counterService.increment("orders"); } public void cancelOrder(){ this.counterService.decrement("orders"); } }

26

Page 27: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Cloud Watch Visualization

27

Page 28: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

The Future

28

Page 29: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud Discovery Client

29

Application

Discovery Client API Gateway

Resources Methods

Consumer

Consumer

Consumer

Page 30: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud Application

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

30

Page 31: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Spring Cloud Controller

@Controllerpublic class SampleController { @RequestMapping("/person/{id}") public Person getPerson(@PathVariable String id) { return new Person("Agim", "Emruli"); }}

31

Page 32: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

API Gateway Declaration

32

Page 33: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Consuming API Gateway Services@Servicepublic class RestMoneyExchangeGateway implements MoneyExchangeGateway { @Autowired @LoadBalanced private RestOperations restTemplate; public Double exchangeMoney(String currency, long amount) { return restTemplate.getForObject(“http://MY-SERVICE/exchange/{currency}/{price}”, Double.class, currency, amount); }}

33

Page 34: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

AWS Lambda Supportpublic class LambdaExample implements RequestHandler<S3EventNotification, String> { @Override public String handleRequest(S3EventNotification input, Context context) { return "result"; } }

34

@Servicepublic class LambdaTest { @LambdaFunction public String receiveNotification(S3EventNotification input) { return "test"; } }

Page 35: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Lambda Function Structure

35

AWS Lambda

API Gateway

IOT

Kinesis

Trigger

Application

Lambda Function

Spring Beans

Lambda Handler

Page 36: Spring Cloud on AWS

Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /

Learn More. Stay Connected.

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

Cloud Native Java with Spring Cloud Services

@springcentral spring.io/blog

@pivotal pivotal.io/blog

@pivotalcf http://engineering.pivotal.io


Recommended