Presentation of my talk about Spring Cloud features that can integrate with AWS, GCP and Azure turning Spring Cloud into a distributed platform that is capable to work with different environments like Kubernetes, Cloud or Local with adoption of Spring abstractions.
26. • @Value & @RefreshScope.
26Configuration Management
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
27. • @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
27Configuration Management
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
28. • @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
• Spring Cloud Config Monitor for push notifications.
28Configuration Management
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
29. • @Value & @RefreshScope.
• Spring Boot Actuator /refresh endpoint.
• Spring Cloud Config Monitor for push notifications.
• Spring Cloud Bus for app refresh notifications.
29Configuration Management
App
(Config Client)
Config
Server
Config Repo
Cloud Bus
43. Use service-name instead of hostname, e.g. http://ServiceName/foo/bar/
43Load Balancing
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
49. Circuit Breaker
Closed – watch requests, keep track of errors.
Open – if there are too many errors, fast fail to a default value.
49
Closed
Open
Success
Too many fails
Fast Fail
50. Circuit Breaker
Closed – watch requests, keep track of errors.
Open – if there are too many errors, fast fail to a default value.
Half-Open – try one request some time later.
50
Closed
Open
Half-Open
Success
Too many fails
Fast Fail
Try one request
Fail
Success
66. Development is simplified down to three simple annotations:
• @EnableBinding - activate connectivity to a message broker.
• @StreamListener - receive data from a channel.
• @SendTo - stream data to a channel.
Spring Cloud Stream
67. The basic channel abstractions are provided by three interfaces:
• Sink – input message channel.
• Source – output message channel.
• Processor – extends Sink and Source.
Spring Cloud Stream
68. Source code for Sink, Source and Processor interfaces:
Spring Cloud Stream
public interface Source {
String OUTPUT = "output";
@Output(Source.OUTPUT)
MessageChannel output();
}
public interface Processor extends Source, Sink {
}
public interface Sink {
String INPUT = "input";
@Input(Sink.INPUT)
SubscribableChannel input();
}
69. Spring Cloud Stream
@Component
public class MyPublisher {
@Autowired
@Qualifier("myOutput")
private MessageChannel output;
public void publish(String s) {
output.send(MessageBuilder.withPayload(s).build());
}
}
public interface MyOutput {
@Input("myOutput")
MessageChannel output();
}
70. Spring Cloud Stream
@Component
public class MyConsumer {
@StreamListener(Sink.INPUT)
public void consume(String s) {
System.out.println(s);
}
}
@Component
public class MyProcessor {
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Integer process(String s) {
return s.length();
}
}
79. 79Beans
Declare function as beans
@SpringBootApplication
public class TestApp {
@Bean
public Function<Flux<String>, Flux<String>> upperCase() {
return flux -> flux.map(String::toUpperCase);
}
80. 80Beans
Declare function as beans
@SpringBootApplication
public class TestApp {
@Bean
public Function<Flux<String>, Flux<String>> upperCase() {
return flux -> flux.map(String::toUpperCase);
}
@Bean
public Supplier<String> helloWorld() {
return () -> "Hello World";
}
81. 81Beans
Declare function as beans
@SpringBootApplication
public class TestApp {
@Bean
public Function<Flux<String>, Flux<String>> upperCase() {
return flux -> flux.map(String::toUpperCase);
}
@Bean
public Supplier<String> helloWorld() {
return () -> "Hello World";
}
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
}
83. 83Beans
@Component
public class HelloWorld implements Supplier<String> {
@Override
public String get() {
return "Hello World";
}
}
@Component
public class UpperCase implements Function<Flux<String>, Flux<String>> {
@Override
public Flux<String> apply(Flux<String> flux) {
return flux.map(String::toUpperCase);
}
}
84. 84Beans
@SpringBootApplication
public class TestApp {
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
}
@Component
public class HelloWorld implements Supplier<String> {
@Override
public String get() {
return "Hello World";
}
}
@Component
public class UpperCase implements Function<Flux<String>, Flux<String>> {
@Override
public Flux<String> apply(Flux<String> flux) {
return flux.map(String::toUpperCase);
}
}
85. Deploy functions as HTTP Endpoints
Web
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-web</artifactId>
</dependency>
86. 86Endpoints
Method Path Request Response Status
GET /{supplier} - Items from the
named supplier
200 OK
POST /{consumer} JSON object or text Mirrors input and
pushes request body
into consumer
202 Accepted
POST /{consumer} JSON array or text
with new lines
Mirrors input and
pushes body into
consumer one by one
202 Accepted
POST /{function} JSON object or text The result of applying
the named function
200 OK
POST /{function} JSON array or text
with new lines
The result of applying
the named function
200 OK
GET /{function}/{item} - Convert the item into
an object and return
the result of applying
the function
200 OK
104. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
Spring Cloud AWS 104
105. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
Spring Cloud AWS 105
106. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
Spring Cloud AWS 106
107. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
Spring Cloud AWS 107
108. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
• Integration
• RDS – automatic data source lookup
Spring Cloud AWS 108
109. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
• Integration
• RDS – automatic datasource lookup
• SQS – point-to-point messaging
Spring Cloud AWS 109
110. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
• Integration
• RDS – automatic data source lookup
• SQS – point-to-point messaging
• SNS – Pub/sub messaging
Spring Cloud AWS 110
111. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
• Integration
• RDS – automatic data source lookup
• SQS – point-to-point messaging
• SNS – Pub/sub messaging
• Kinesis – Spring Cloud Stream
Spring Cloud AWS 111
112. • Configuration
• Environment configuration based on EC2 & CloudFormation metadata
• Parameter Store & Secrets Manager as a bootstrap property source
• Abstraction
• S3 through Spring ResourceLoader
• SES through Spring Email
• ElastiCache through Spring Cache
• Integration
• RDS – automatic data source lookup
• SQS – point-to-point messaging
• SNS – Pub/sub messaging
• Kinesis – Spring Cloud Stream
• Lambda – Spring Cloud Function
Spring Cloud AWS 112
116. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
Spring Cloud GCP 116
117. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
Spring Cloud GCP 117
118. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
• Google Cloud Vision API Template
Spring Cloud GCP 118
119. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
• Google Cloud Vision API Template
• Integration
• Spring Data Cloud SQL
Spring Cloud GCP 119
120. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
• Google Cloud Vision API Template
• Integration
• Spring Data Cloud SQL
• Spring Data Cloud Spanner
Spring Cloud GCP 120
121. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
• Google Cloud Vision API Template
• Integration
• Spring Data Cloud SQL
• Spring Data Cloud Spanner
• Spring Data Cloud Datastore
Spring Cloud GCP 121
122. • Configuration
• Google Cloud Config
• Abstraction
• Spring Resource Abstraction for Google Cloud Storage
• Google Cloud Stackdrive Logging & Tracing
• Google Cloud Vision API Template
• Integration
• Spring Data Cloud SQL
• Spring Data Cloud Spanner
• Spring Data Cloud Datastore
• Spring Cloud GCP Pub/Sub
Spring Cloud GCP 122
126. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
Spring Cloud Azure 126
127. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
Spring Cloud Azure 127
128. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
• Integration
• Spring Data Azure Data Services
Spring Cloud Azure 128
129. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
• Integration
• Spring Data Azure Data Services
• Spring Data Azure Redis Cache
Spring Cloud Azure 129
130. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
• Integration
• Spring Data Azure Data Services
• Spring Data Azure Redis Cache
• Spring Data Azure Cosmos DB SQL API
Spring Cloud Azure 130
131. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
• Integration
• Spring Data Azure Data Services
• Spring Data Azure Redis Cache
• Spring Data Azure Cosmos DB SQL API
• Spring Data Gremlin for Azure Cosmos DB Graph API
Spring Cloud Azure 131
132. • Configuration
• Azure Key Vault
• Abstraction
• Azure Storage – Spring Resource
• Azure AD –Spring Security & OAuth2
• Integration
• Spring Data Azure Data Services
• Spring Data Azure Redis Cache
• Spring Data Azure Cosmos DB SQL API
• Spring Data Gremlin for Azure Cosmos DB Graph API
• Spring Cloud Stream Azure Event Hub
Spring Cloud Azure 132
135. • Configuration
• PropertySource based on ConfigMaps & Secrets with configuration reload upon
changes available
• Asbtraction
• DiscoveryClient abstraction
Kubernetes 135
136. • Configuration
• PropertySource based on ConfigMaps & Secrets with configuration reload upon
changes available
• Asbtraction
• DiscoveryClient abstraction
• Client-side load balancing with Ribbon integration
Kubernetes 136
137. • Configuration
• PropertySource based on ConfigMaps & Secrets with configuration reload upon
changes available
• Asbtraction
• DiscoveryClient abstraction
• Client-side load balancing with Ribbon integration
• Integration
• HealthIndicator integration
Kubernetes 137
138. • Configuration
• PropertySource based on ConfigMaps & Secrets with configuration reload upon
changes available
• Asbtraction
• DiscoveryClient abstraction
• Client-side load balancing with Ribbon integration
• Integration
• HealthIndicator integration
• Kubernetes & Istio awareness through corresponding spring profiles
Kubernetes 138