using Spring and MongoDB on Cloud Foundry

  • 951 views
Uploaded on

This talk introduces how to build MongoDB applications with Spring Data MongoDB on Cloud Foundry. Spring Data provides rich support for easily building applications that work on multiple data stores.

This talk introduces how to build MongoDB applications with Spring Data MongoDB on Cloud Foundry. Spring Data provides rich support for easily building applications that work on multiple data stores.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
951
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
63
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • Hello, thank you or having me. Im pleased to have the opportunity to introduce you today to Spring and the SpringSource Tool Suite \n\nMy anem is Josh Long. I serve as the developer advocate for the Spring framework. I’ve used it in earnest and advocated it for many years now. i’m an author on 3 books on the technology, as well as a comitter to many of the Spring projects. Additionally, I take community activism very seriously and do my best to participate in the community. Sometimes this means answering question on Twitter, or in the forums, or helping contribute to the InfoQ.com and Artima.com communities\n
  • \n
  • these different framerworks let u tackle any problem youre likely to want to solve today \n- we support javee1.4 + 1.5 + 1.6; \n\nsits above target platform \nruns in cloud \n\n
  • \n
  • Oracle RAC clustering is very expensive. $70K/CPU according to list. Even at ½ the cost, it’s still really expensive to build out a horizontal data access grid. \n
  • The amount of log data amassed in Facebook’s operations is staggering. Rothschild said Facebook manages more than 25 terabytes of data per day in logging data, which he said was the equivalent of about 1,000 times the volume of mail delivered daily by the U.S. Postal Service.\n\nBASE (basically available, soft state, eventually consistent)\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Using Spring and MongoDB withCloudFoundryJosh Long@starbuxmanSpring Developer AdvocateSpringSource, a division of VMware © 2009 VMware Inc. All rights reserved
  • 2. About Josh Long Spring Developer Advocate @starbuxman josh.long@springsource.com th si is im po rta nt ! Free Book! SpringSource.org/roo 2
  • 3. Spring 3
  • 4. Spring’s aim: bring simplicity to Java development data web tier integration batch access & service tier & mobile processing / NoSQL / RIA messaging Big Data The Spring frameworkthe cloud: lightweight traditional CloudFoundry WebSphere tc Server VMForce JBoss AS Tomcat Google App Engine WebLogic Jetty Amazon Web Services (on legacy versions, too!) 4
  • 5. Spring Data 5
  • 6. Data Access Challenge #1: Scale Horizontally 6
  • 7. Data Access Challenge #2: Heterogeneous data access needs 7
  • 8. New demands on data access•... until we neededinexpensive horizontalscaling for some large webbased applications ...• ... and we needed todeploy our apps in thecloud ... * image courtesy of Bitcurrent 8
  • 9. NoSQL offers several data store categoriesKey-Value Column Document Graph Redis, Cassandra, MongoDB Neo4J Riak HBase 9
  • 10. NoSQL offers several data store categoriesKey-Value Column Document Graph MongoDB (who cares about the rest?) 10
  • 11. 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) 11
  • 12. http://www.springsource.org/spring-data•Spring Data Key-value•Spring Data Document•Spring Data Graph•Spring Data Column•Spring Data Blob•Spring Data JPA Repository / JDBC Extensions•Spring Gemfire / Spring Hadoop ...•Grails iNcOnSeQuentiaL 12
  • 13. 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 13
  • 14. Spring MongoDB 14
  • 15. 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(@Document, @Id, @DbRef) •Annotation based•MongoRepository •Built on Hades support for JPA Repositories 15
  • 16. Simple Domain Class 16
  • 17. Mongo TemplateDirect Usage of the Mongo Template: 17
  • 18. Mongo TemplateDirect Usage of the Mongo Template: Insert into “Person” Collection 17
  • 19. Mongo TemplateDirect Usage of the Mongo Template: findOne using query: { "name" : "Joe"} in db.collection: database.Person 17
  • 20. Mongo TemplateDirect Usage of the Mongo Template: Dropped collection [database.person] 17
  • 21. Generic RepositoryInterface for generic CRUD operations on a repository for a specific type 18
  • 22. Paging and Sorting RepositoryPaging and Sorting Repository: Extends “CrudRepository” 19
  • 23. Paging and Sorting RepositoryPaging and Sorting Repository: Extends “CrudRepository” Usage: 19
  • 24. Custom RepositoryCustom Repository: 20
  • 25. Custom RepositoryCustom Repository:Keywords :Keyword Sample Logical resultGreaterThan findByAgeGreaterThan(int age) {"age" : {"$gt" : age}}LessThan findByAgeLessThan(int age) {"age" : {"$lt" : age}}Between findByAgeBetween(int from, int to) {"age" : {"$gt" : from, "$lt" : to}}NotNull findByFirstnameNotNull() {”firstname" : {"$ne" : null}}Null findByFirstnameNull() {”firstname" : null}Like findByFirstnameLike(String name) "firstname" : firstname} (regex) 20
  • 26. Cross Store 21
  • 27. JPA and MongoDB JPA “Customer” with a “SurveyInfo” Document 22
  • 28. Using a Cross-Store Saving a Customer with a SurveryInfo 23
  • 29. Using a Cross-Store Saving a Customer with a SurveryInfo Create Customer 23
  • 30. Using a Cross-Store Saving a Customer with a SurveryInfo Create SurveyInfo 23
  • 31. Using a Cross-Store Saving a Customer with a SurveryInfo Assign Survey to Customer 23
  • 32. Using a Cross-Store Saving a Customer with a SurveryInfo Save 23
  • 33. Using a Cross-Store Saving a Customer with a SurveryInfo Save Mongo Document: 23
  • 34. Cloud Foundry 24
  • 35. Cloud Foundry github.com/cloudfoundry cloudfoundry.org @cloudfoundry Supports: • Languages: Java, Scala, Node.js, Grails, Ruby/Rails/Sinatra, etc. • Services: MongoDB, Redis, MySQL, PostgreSQL, RabbitMQ ecosystem forks: • AppFog - PHP • Stacato: Python, Perl, etc., from ActiveState 25
  • 36. Choice of clouds .js ce rfa Ap te Data Private p In lic Services Clouds er at io vid n Public o Se Msg Pr Services r Clouds vic d ou e In Cl Micro te Other r Services Clouds fa e c 26
  • 37. Choice of clouds .js ce rfa Ap te Data Private p In lic Services Clouds … er at io vid n Public o Se Msg Pr Services r Clouds vic d ou e In .COM Cl Micro te Other r Services Clouds fa e c 26
  • 38. Setting up Cloud Foundry Demo 27
  • 39. Accessing Services Bound to Cloud Foundry (producer)private String mongoDatabaseServiceName = "survey-mongo";@Beanpublic CloudEnvironment cloudEnvironment() { return new CloudEnvironment();}@Beanpublic MongoServiceInfo mongoServiceInfo() { return cloudEnvironment().getServiceInfo( mongoDatabaseServiceName, MongoServiceInfo.class);}@Beanpublic MongoDbFactory mongoDbFactory() { MongoServiceCreator msc = new MongoServiceCreator(); MongoDbFactory db = msc.createService(mongoServiceInfo());} 28
  • 40. Accessing Services Bound to Cloud Foundry (consumption)@Inject private Mongo mongo ;@Inject private MongoTemplate mongoTemplate; 29
  • 41. Cloud Foundry MongoDB Demo 30
  • 42. Where to Find More Spring Data Project: http://bit.ly/spring-data CloudFoundry Samples: http://bit.ly/cloudfoundry-samples MicroCloud Foundry for Spring Developers http://bit.ly/mcf4spring Spring Data Mongo on Cloud Foundry (webinar, 12/01/2011) http://bit.ly/spring-mongo-cloudfoundry 31