This document discusses how to simplify cloud applications using Spring Cloud. It describes Spring Cloud's goals of abstracting over cloud services and environments. It covers using Java and XML configuration, scanning for services, and acquiring services. It also discusses Spring Cloud's extensibility for cloud platforms, services, and frameworks. The document includes demos of using Spring Cloud on Cloud Foundry, Heroku, and with Hadoop. It describes the integration with Spring Boot.
11. Cloud Apps Awareness:
Heroku Instance Information
• Individual env variables
!
PORT
12345
!
DYNO
web.1
!
6
12. Cloud Apps Awareness: Heroku Services
• One environment variable per service
!
HEROKU_POSTGRESQL_PURPLE_URL
postgres://user:pass@host.amazonaws.com:5432/db
!
REDISCLOUD_URL
redis://rediscloud:pass@host.garantiadata.com:19038
REDISTOGO_URL
redis://redistogo:pass@host.redistogo.com:9139
7
13. Spring Cloud Goals
• Abstraction over cloud services and application environment
• Implementation for multiple cloud platforms
• Cloud Foundry
• Heroku
• Local testing simulating a cloud-like environment
• Extensibility without modifying the core code
• Cloud Connector
• Service Creator
8
15. Scanning for services
!!
@Configuration
@CloudScan
public class CloudConfig {
!
}
10
16. Scanning for services
!!
@Configuration
@CloudScan
public class CloudConfig {
!
}
10
17. Taking over control
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource dataSource() {
return connectionFactory().dataSource();
}
!
@Bean
public MongoDbFactory mongoDb() {
return connectionFactory().mongoDbFactory();
}
}
11
18. Taking over control: Working with specific services
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource inventoryDataSource() {
return connectionFactory().dataSource("inventory-service");
}
!
@Bean
public DataSource customerDataSource() {
return connectionFactory().dataSource("customers-service");
}
}
12
19. Taking over control: Configuring Services
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource inventoryDataSource() {
PoolConfig poolConfig = new PoolConfig(20, 200);
ConnectionConfig connectionConfig =
new ConnectionConfig("characterEncoding=UTF-8");
DataSourceConfig serviceConfig =
new DataSourceConfig(poolConfig, connectionConfig);
return connectionFactory().dataSource(
"inventory-service", serviceConfig);
}
}
13
20. Acquiring generic services
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
public Search search() {
return connectionFactory().service(
"search-service", Search.class);
}
}
14
45. Registering Cloud Connector
!
• Add a line with the class name to
/META-INF/services/org.springframework.cloud.CloudConnector!
!!!
• Cloud Foundry example:!
org.springframework.cloud.cloudfoundry.CloudFoundryConnector
!
•Heroku example:!
org.springframework.cloud.heroku.HerokuConnector
35
48. Cloud Service Extensibility
public interface ServiceInfoCreator<SI extends ServiceInfo, SD> {
36
public boolean accept(SD serviceData);
!
public SI createServiceInfo(SD serviceData);
}
public interface ServiceInfo {
public String getId();
}
49. Registering Service Info Creators
• Each Cloud Connector can choose any scheme it prefers
!
• Cloud Foundry Cloud Connector example
/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator
37
50. Registering Service Info Creators
• Each Cloud Connector can choose any scheme it prefers
!
• Cloud Foundry Cloud Connector example
/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator
37
org.springframework.cloud.cloudfoundry.MysqlServiceInfoCreator
org.springframework.cloud.cloudfoundry.PostgresqlServiceInfoCreator
org.springframework.cloud.cloudfoundry.RedisServiceInfoCreator
org.springframework.cloud.cloudfoundry.MongoServiceInfoCreator
org.springframework.cloud.cloudfoundry.AmqpServiceInfoCreator
org.springframework.cloud.cloudfoundry.MonitoringServiceInfoCreator
org.springframework.cloud.cloudfoundry.SmtpServiceInfoCreator
org.springframework.cloud.cloudfoundry.OracleServiceInfoCreator
51. Framework extensibility
• Mapping ServiceInfo to framework-specific service connector
• RelationalServiceInfo -> DataSource
• MongoServiceInfo -> MongoDbFactory
• ...
38
public interface ServiceConnectorCreator<SC, SI extends ServiceInfo> {
!
SC create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig);
Class<SC> getServiceConnectorType();
!
Class<?> getServiceInfoType();
}
52. Framework extensibility registration
• Each framework may choose any mechanism!
!
• Spring Connection Creator example!
/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator
39
53. Framework extensibility registration
• Each framework may choose any mechanism!
!
• Spring Connection Creator example!
/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator
39
org.springframework.cloud.service.relational.MysqlDataSourceCreator
org.springframework.cloud.service.relational.PostgresqlDataSourceCreator
org.springframework.cloud.service.relational.OracleDataSourceCreator
org.springframework.cloud.service.keyval.RedisConnectionFactoryCreator
org.springframework.cloud.service.document.MongoDbFactoryCreator
org.springframework.cloud.service.messaging.RabbitConnectionFactoryCreator
org.springframework.cloud.service.smtp.MailSenderCreator
57. Auto-configuration
• Add spring-cloud dependencies in project
• … that’s it
!
!
• The same effect as adding @CloudScan
43
Available in Spring Boot 1.2.x
58. Spring Cloud starter
!
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud</artifactId>
</dependency>
44
Available in Spring Boot 1.2.x
59. What’s next
• Support for many more services
• Elasticsearch
• Memcache
• Riak
• Cassandra
• Neo4j
• ...
• Support for other cloud platforms
• Support for other frameworks?
45
60. What’s next
• Support for many more services
• Elasticsearch
• Memcache
• Riak
• Cassandra
• Neo4j
• ...
• Support for other cloud platforms
• Support for other frameworks?
45
Community Contributions Welcome!