Spring is the most popular and productive enterprise Java development framework in the world, and has always provided developers with portability and choice. The cloud should be no different. Spring applications work flawlessly on all the major platform-as-a-service clouds including Heroku, Google App Engine, and Cloud Foundry. This session will focus on how to design, and create, modern enterprise applications using Spring 3 that are portable across cloud environments.
3. About Jennifer
•Long time SpringSource-er
•Contributed to many Spring and SpringSource projects
•Cloud Foundry Engineer
•Focused on framework support
3
4. Agenda
•Why Cloud? Why PaaS?
•Spring Framework for the Cloud
•Data
Developing NoSQL applications for the Cloud with Spring
•Integration
Cloud application integration with RabbitMQ and Spring
•Wrap up
4
5. Traditional web application architecture
• Browser client
• Monolithic WAR
• RDBMS
Desktop MySQL
Apache WAR
Browser Database
Tomcat
Simple to develop
Simple to test
Simple to deploy
Simple to scale: just add Apache + more
Tomcats
5
6. New kinds of clients
Smart phones overtake PCs in Q4 2010
6
7. Users expect a rich, dynamic and interactive experience
on mobile devices and desktop
gh
ou
d en
oo
’t g
HTTP Request isn
Desktop
ct ure Java Web
e
Browser
hit
HTML/Javascript Application
I arc
ty le U
Olds
7
8. Users expect a rich, dynamic and interactive experience on mobile
devices and desktop
HTML5 WS Request
Javascript
Application XML/JSON response Web Services
Mobile and Desktop
Browser Web Socket/Eventing
8
9. Popular social networks
•Applications need to integrate with them
•Application integration problem
•Scaling graphs is challenging
•Application go viral through social networks
•Very rapid growth
•Capacity planning nightmare
9
10. Need scalable architectures to handle massive loads
•Application tier
•Replicated/clustered servers
•Modular so that components can be scaled differently
•Asynchronous architecture - communication via a message broker
•Database tier
•Replication
•Sharding
•Polyglot persistence: Relational, NoSQL, NewSQL databases
10
11. Data Explosion: Data Volumes increasing at 60% per year
Horizontally scalable, distributed NoSQL Databases 20
11
Eventual consistency rather than ACID
12. Scaling development
WAR
Front End
Scalable
User Management
!=
Search
development
Ordering
• Forces multiple developers/teams to
efforts
synchronize development
• Obstacle to frequent, independent deployments
• Increases risk of failure - need to redeploy everything to change one
thing
12
13. Scaling development
•Need “SOA” approach
•Partition application into set of services
•Partition by noun or by verb
•manages their own release schedule. and
Each team is responsible for a service
•New code updates frequently
•Mature services upgrade infrequently
User
User
Management
Management
Front-end
Search
Search
Front-End
Ordering
Ordering
Front-End
13
14. Modern application architecture
User
Management
MySQL
Tomcat
Desktop
Browser
Native NodeJS Search
NodeJS
Mobile front-end
front-end
Application application
application
RabbitMQ
Tomcat
HTML5 Mongo
mobile
application
Redis
Ordering
Tomcat
14
15. Three layers of cloud computing
SaaS
PaaS
Need to be here
IaaS
15
16. What you need is PaaS =
Easy deployment
Services:
Application management Database
+ Blob storage
Easy scaling up and down Messaging
...
16
18. Agenda
•Why Cloud? Why PaaS?
•Spring Framework for the Cloud
•Data
Developing NoSQL applications for the Cloud with Spring
•Integration
Cloud application integration with RabbitMQ and Spring
•Wrap up
18
19. Spring’s aim:
bring simplicity to java development
data
web tier
batch integration & access
& service tier mobile
processing messaging / NoSQL /
RIA
Big Data
The Spring framework
the cloud: lightweight traditional
CloudFoundry WebSphere
tc Server
Google App Engine JBoss AS
Tomcat
Amazon Web Services WebLogic
Jetty
Heroku (on legacy versions, too!)
19
20. At its core, the Spring Framework...
•developing enterprise Java™ applications
Provides comprehensive infrastructural support for
•Spring deals with the plumbing
•So you can focus on solving the domain problem
20
21. Spring 3.1 Environment Abstraction
•Bean definitions for a specific environment (Profiles)
•e.g. development, testing, production
•Possibly different deployment environments
•Activate profiles by name
•spring.profiles.active system property
•Other means outside deployment unit
•“default” profile activates if no other profiles specified
•Custom resolution of placeholders
•Dependent on the actual environment
•Ordered property sources
21
23. Java Configuration with Profiles
@Configuration
@Profile(“local”)
public class LocalDataSourceConfiguration {
@Bean public javax.sql.DataSource dataSource() { ... }
}
@Configuration
@Profile(“cloud”)
public class CloudDataSourceConfiguration {
@Bean public javax.sql.DataSource dataSource() { ... }
}
23
24. Agenda
•Why Cloud? Why PaaS?
•Spring Framework for the Cloud
•Data
Developing NoSQL applications for the Cloud with Spring
•Integration
Cloud application integration with RabbitMQ and Spring
•Wrap up
24
27. NoSQL offers several data store categories
Key-Value Column Document Graph
Redis, Cassandra, MongoDB Neo4J
Riak HBase
27
28. NoSQL offers several data store categories
Key-Value Column Document Graph
MongoDB
28
29. Spring Framework
built-in data access support
•Transaction abstractions
•Common data access exception hierarchy
•JDBC - JdbcTemplate
•ORM - Hibernate, JPA support
•OXM - Object to XML mapping
•Serializer/Deserializer strategies (Spring 3.0)
•Cache support (Spring 3.1)
29
31. Spring Data Building Blocks
•Low level data access APIs
✓MongoTemplate, RedisTemplate ...
•Object Mapping (Java and GORM)
•Cross Store Persistence Programming model
•Generic Repository support
•Productivity support in Roo and Grails
31
33. Spring Data Document
Mongo
•MongoTemplate interface for mapping Mongo documents
•
MongoConverter
•SimpleMongoConverter for basic POJO mapping support
•Leverage Spring 3.0 TypeConverters and SpEL
•Exception translation
•Advanced Mapping
•Annotation based (@Document, @Id, @DbRef)
•MongoRepository for JPA Repositories
•Built on Hades support
33
35. Mongo Template
Direct Usage of the Mongo Template:
Insert into “Person”
Collection
findOne using query: { "name" : "Joe"}
in db.collection: database.Person
Dropped collection [database.person]
35
43. Agenda
•Why Cloud? Why PaaS?
•Spring Framework for the Cloud
•Data
Developing NoSQL applications for the Cloud with Spring
•Integration
Cloud application integration with RabbitMQ and Spring
•Wrap up
43
44. wgrus-monolithic.war
@Controller
StoreFront
Widget Gadget Accounting Shipping
InventoryService InventoryService Service Service
RDBMS
44
45. It’s simple to develop but ....
•Lack of scalability
•Scale through replication
•Non-replicable component => nothing can be replicated
•Can’t scale different parts of the application differently
•Lack of deployability
•Deploy it all in one go
•Increased risk of something breaking
•Applications are brittle
•Store can’t accept orders unless all services are available
•Failure (e.g. memory leak) in one component can take down every other
•Monolingual
•Can’t use non-JVM server-side technologies: NodeJS, Rails
45
47. wgrus-billing.war
Accounting
Service
wgrus-inventory.war
wgrus-store.war Widget
InventoryService
Message
StoreFront Broker MySQL
wgrus-inventory.war
Gadget
InventoryService
wgrus-shipping.war
Shipping
Service
47
48. RabbitMQ – Messaging that Just Works
Robust
High-performance
Easy to use
AMQP LEADER
49. Spring AMQP
• Encapsulates low-level details Producer Consumer
• Simplifies sending and receiving
of messages
Amqp Listener
Template Container
Spring AMQP
AMQP
50. Spring Integration
• Builds on Spring framework
• High-level of abstraction for building message
based applications
• Implements EAI patterns
• Provides applicationfor exchanging messages
between
plumbing
components
• Promotes loosely coupled components
• Integrates with JMS, AMQP, HTTP, Email, File
infrastructure:
external messaging
transfer
50
51. Spring Integration concepts
•Message channel
•Virtual pipe connecting producer and consumer
•Message endpoints
•The filter of a pipes-and-filter architecture
•Read from and/or write to channel
•Endpoint types
•Transformer
•Filter
•Router
•Splitter
•Aggregator
•ServiceActivator
•Inbound channel adapter - read from external source, writes to channel
•destinationchannel adapter - read from channel write to external
Outbound
51
52. Example of reconfigurability - local
@Service
public class OrderServiceImpl { @Service
public class ShippingServiceImpl {
@Autowired
private ShippingService shippingService; public void shipOrder(String orderId) {
System.out.println("shipped order: " +
public void placeOrder() { orderId);
String orderId = generateOrderId(); }
…
shippingService.shipOrder(orderId); }
}
}
Order Shipping
Service service
Messaging
Gateway
Channel Service
Activator
52
53. Example of reconfigurability - distributed
Code unchanged in new deployment
Order Shipping
Service service
Messaging
Gateway RabbitMQ
Channel AMQP AMQP Channel Service
Activator
53
57. Inventory flow
Json to credit check inventory inventory Object to
AMQP inventory AMQP
Object enricher encricher AMQP Out JSON
inventory
router
credit check
credit check Content Based
service Router
activator
Credit
Service
widget gadget
inventory inventory
service service
57
58. Shipping flow
shipping
service
Json to
AMQP shipping Service
Object
order Activator
channel
58
60. Agenda
•Why Cloud? Why PaaS?
•Spring Framework for the Cloud
•Data
Developing NoSQL applications for the Cloud with Spring
•Integration
Cloud application integration with RabbitMQ and Spring
•Wrap up
60
62. Where to Find More
•http://bit.ly/spring-data
Spring Data Project:
•http://www.springsource.org/spring-integration
Spring Integration Project:
•https://github.com/jencompgeek/cloudfoundry-samples/tree/master/cross-
Mongo Cross Store Sample:
store
•https://github.com/markfisher/springone-wgrus
WGRUS Sample:
•http://bit.ly/cloudfoundry-samples
CloudFoundry Samples:
• Sign up for (free) Cloud Foundry
http://www.cloudfoundry.com
•http://bit.ly/mcf4spring for Spring Developers
MicroCloud Foundry
•Cloud Foundry and Spring YouTube Channels
62