Spring into the Cloud - JDC2012 Cairo, Egypt

1,883 views

Published on

Let's face it, the cloud's here to stay. Cloud Foundry, introduced to rave reviews in the NoSQL, Node.js, Ruby, Scala and Java communities, represents the most promising, most open cloud platform for Java and Spring applications today, and tomorrow. In this talk, we introduce Cloud Foundry and describe it's architecture.

You will learn about why Spring is the ideal cloud computing platform. We describe how Cloud Foundry can be used with both existing Spring applications and new ones leveraging Spring 3.1. You will learn how to use Spring Data to develop NoSQL applications on Cloud Foundry, and how to integrate applications with RabbitMQ and Spring AMQP.

Published in: Technology, Business

Spring into the Cloud - JDC2012 Cairo, Egypt

  1. 1. Spring into the CloudChris RichardsonAuthor of POJOs in ActionFounder of the original CloudFoundry.com@crichardsoncrichardson@vmware.com 1
  2. 2. Presentation goal Cloud Foundry simplifies the development and deployment of modern applications Spring is the ideal cloud computing platform 2
  3. 3. About Chris 3
  4. 4. About Chris 4
  5. 5. (About Chris) 5
  6. 6. About Chris() 6
  7. 7. About Chris 7
  8. 8. About Chris http://www.theregister.co.uk/2009/08/19/springsource_cloud_foundry/ 8
  9. 9. About Chris Developer Advocate for CloudFoundry.com Signup at http://cloudfoundry.com Promo code: EgyptJUG 9
  10. 10. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures
  11. 11. Traditional web application architecture WAR StoreFront Accounting Service MySQL Desktop Database Apache Browser InventoryService Shipping ServiceSimple to Tomcat develop test deploy scale Or is it? 11
  12. 12. Let’s imagine you want to run aperformance test... ?How long to get the servers?Who is going to set up the servers?Who is going to set up Apache,Tomcat, and MySQL?
  13. 13. And things are changing:This simple, monolithic architecture is inadequate 13
  14. 14. New kinds of clients Smart phones overtake PCs in Q4 2010 14
  15. 15. Users expect a rich, dynamic and interactive experience on mobile devices and desktop h oug d en oo ’t g HTTP Request e isn r ctu Desktop Java Web e hit Browser HTML/Javascript Application c I ar ty le U s Old 15
  16. 16. Need to handle massive loads and the data explosion Need scalable architectures 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 16
  17. 17. Scaling development WAR StoreFront Accounting Service Scalable != InventoryService development Shipping Service Forces multiple developers/teams to synchronize development efforts Obstacle to frequent, independent deployments Increases risk of failure - need to redeploy everything to change one thing 17
  18. 18. Modern application architecture billing.warDesktop AccountingBrowser Service StoreUINative Mobile NodeJS NodeJS inventory.warApplication front-end MySQL application StoreUI StoreUI InventoryServiceHTML5 mobileapplication StoreUI Redis shipping.war RabbitMQ Mongo ShippingService 18
  19. 19. Developing and testing these applications is even more challenging 19
  20. 20. Let’s imagine you are fixing a bugand want to run some JUnitintegration tests... ?Who is going to install and configureyour sandbox: MySQL, RabbitMQ,MongoDB, ....?
  21. 21. Let’s imagine you have fixed a bugand want to run some functionaltests... ?How long to purchase the servers?Who is going to set up the servers?Who is going to install and configureMySQL, RabbitMQ, MongoDB, ....?
  22. 22. Platform-as-a-Service is the solution Easy deployment Services: Database Application management + Blob storage Messaging Easy scaling up and down ... 22
  23. 23. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures
  24. 24. About Cloud Foundry .js Ap p lica Private   7o Clouds   n  S Data Services erv … i ce  In ter e fac fac ter Public e r  In Clouds ide Msg Services ov  Pr ud Cl o Micro .COM Clouds Other Services 24
  25. 25. Cloud Foundry.COM Cloud Foundry Runtimes & Frameworks Services vCenter / vSphere Infrastructure
  26. 26. What is a Micro Cloud? Or Entire Cloud Running inside of a single VMSignup @ http://cloudfoundry.com/micro 26
  27. 27. Cloud Foundry.ORG Cloud Foundry The Cloud Foundry Source Code Download Setup Setup Scripts Deploy Behind Environment Firewall Code 27
  28. 28. Vibrant open-source ecosystem AppFog.com • Community lead for PHP • PaaS for PHP Joyent • Community lead for Node.js ActiveState • Community lead for Python • Stackato private PaaS
  29. 29. Cloud Foundry - Architecture Web Web Web100’s of DEAs Load Balancers Load Balancers App Load Balancers App App Message Bus Message Bus Message Bus (NATS) (NATS) (NATS) DEAs DEAs DEAs Routers Routers Routers DB DB DB Cloud Cloud Controllers Cloud Controllers Controllers Services Health Health Services Health Manager Services Manager Manager Web Service API
  30. 30. Lets deploy an application
  31. 31. Create an application $ mvn archetype:generate … 18: internal -> maven-archetype-webapp (A simple Java web application) … Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/1 6/17/18/19/20/21/22/23/24/25/26/27/28/ 29/30/31/32/33/34/35/36/37/38/39/40/41 ) 15: : 18 … $ mvn package …
  32. 32. Options for using Cloud Foundry 32
  33. 33. Using the Cloud Foundry CLI CLI Application name Dir containing WAR vmc push cf1 --path target --url cer-cf1.cloudfoundry.com Application URL
  34. 34. Deploy the application $ vmc push cf1 --path target --url cer-cf1.cloudfoundry.com Detected a Java Web Application, is this correct? [Yn]: Memory Reservation [Default:512M] (64M, 128M, 256M, 512M, 1G or 2G) Creating Application: OK Would you like to bind any services to cf1? [yN]: Uploading Application: Checking for available resources: OK Packing application: OK Uploading (2K): OK Push Status: OK Starting Application: OK
  35. 35. Access the application $ curl cer-cf1.cloudfoundry.com <html> <body> <h2>Hello World!</h2> </body> </html>
  36. 36. Change the application $ vi src/main/webapp/index.jsp $ mvn package
  37. 37. Update the running application $ vmc update cf1 --path target Uploading Application: Checking for available resources: OK Packing application: OK Uploading (2K): OK Push Status: OK Successfully updated Application: cf1 Stopping Application: OK Starting Application: OK
  38. 38. Access it again $ curl cer-cf1.cloudfoundry.com <html> <body> <h2>This is Cloud Foundry</h2> </body> </html>
  39. 39. Scale the application $ vmc instances cf1 +2 Scaling Application instances up to 3: OK $ vmc stats cf1 +----------+-------------+----------------+--------------+--------------+ | Instance | CPU (Cores) | Memory (limit) | Disk (limit) | Uptime | +----------+-------------+----------------+--------------+--------------+ | 0 | 1.2% (4) | 90.6M (512M) | 8.5M (2G) | 0d:0h:3m:3s | | 1 | 9.5% (4) | 60.9M (512M) | 8.4M (2G) | 0d:0h:0m:17s | | 2 | 9.4% (4) | 55.5M (512M) | 8.4M (2G) | 0d:0h:0m:17s | +----------+-------------+----------------+--------------+--------------+
  40. 40. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures
  41. 41. Available services 41
  42. 42. Creating a service instance $ vmc create-service mysql --name mysql1 Creating Service: OK $ vmc services ============== System Services ============== +------------+---------+---------------------------------------+ | Service | Version | Description | +------------+---------+---------------------------------------+ | mongodb | 1.8 | MongoDB NoSQL store | | mysql | 5.1 | MySQL database service | | postgresql | 9.0 | PostgreSQL database service (vFabric) | | rabbitmq | 2.4 | RabbitMQ messaging service | | redis | 2.2 | Redis key-value store service | +------------+---------+---------------------------------------+ =========== Provisioned Services ============ +-------------+---------+ | Name | Service | +-------------+---------+ | mysql1 | mysql | +-------------+---------+
  43. 43. Typical Spring application is cloud ready<beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" > <property name="driverClassName"! ! ! value="com.mysql.jdbc.Driver" /> <property name="url"! value="jdbc:mysql://localhost:3306/cf" /> <property name="username" value="cfuser" /> <property name="password" value="cfpassword" /> … </bean> class SomeClass { @Autowired private DataSource dataSource; }
  44. 44. Deploying it $ vmc push cer-spring --path web/target/ Application Deployed URL [cer-spring.cloudfoundry.com]: Detected a Java SpringSource Spring Application, is this correct? [Yn]: Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]: Creating Application: OKWould you like to bind any services to cer-spring? [yN]: y Would you like to bind any services to cer-spring? [yN]: yWould you like to use anan existing provisioned service? [yN]: y Would you like to use existing provisioned service? [yN]: yThe The following provisioned servicesavailable following provisioned services are are available 1: mysql11: mysql1 2: mysql-135e02: mysql-135e0Please select one you wish to use:use: 1 Please select one you wish to 1Binding Service [mysql1]: OK OK Binding Service [mysql1]: Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (12K): OK
  45. 45. DataSource bean is reconfigured automatically<beans> <bean id="dataSource" class="…"> … DataSource for MySQL instance … </bean></beans> class SomeClass { @Autowired private DataSource dataSource; }
  46. 46. Using database tools
  47. 47. Using Caldecott… $ vmc tunnel 1: mysql-135e0 2: mysql1 Which service to tunnel to?: 2 Password: ******** Stopping Application: OK Redeploying tunnel application caldecott. Uploading Application: Checking for available resources: OK Packing application: OK Uploading (1K): OK Push Status: OK Binding Service [mysql1]: OK Staging Application: OK Starting Application: OK Getting tunnel connection info: OK Service connection info: username : uMe6Apgw00AhS password : pKcD76PcZR7GZ name : d7cb8afb52f084f3d9bdc269e7d99ab50 Starting tunnel to mysql1 on port 10000. 1: none 2: mysql Which client would you like to start?: 2
  48. 48. …Using Caldecott Launching mysql --protocol=TCP --host=localhost --port=10000 -- user=uMe6Apgw00AhS --password=pKcD76PcZR7GZ d7cb8afb52f084f3d9bdc269e7d99ab50 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 10944342 Server version: 5.1.54-rel12.5 Percona Server with XtraDB (GPL), Release 12.5, Revision 188 Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type help; or h for help. Type c to clear the current input statement. mysql>
  49. 49. Testing scenario Create MySQL service instance Use Caldecott to tunnel database Populate DB using mysql+sql scripts Deploy application bound to database Test the application … Delete application and database
  50. 50. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures
  51. 51. Spring programming model Benefits: •Improved developer productivity •Higher quality code •Portability across Dependency Injection application servers POJOPortable Service Aspect-OrientedAbstractions Programming(Transactions, dataaccess, …) 51
  52. 52. Spring is ideal for the cloud environment Yet another environment for your application to run in • Different Java runtime • Different databases – sometimes not relational! Dynamic environment: • Servers come and go • IP addresses change Must integrate with in-house applications: • RPC • Asynchronous messaging To leverage elasticity your application must be architected to scale up and down • Asynchronous, loose coupling = Problems already solved by the Spring framework
  53. 53. Spring 3.1 features for cloud applications 53
  54. 54. Spring configuration options Auto-reconfiguration Cloud Foundry Runtime <cloud:*/> namespace CloudEnvironment API VCAP_APPLICATION, VCAP_SERVICES env vars
  55. 55. VCAP_APPLICATION { "instance_id": "e53853fe21d5d740aadf7ddcc0670b4e", "instance_index": 0, "name": "cer-spring", "uris": ["cer-spring.cloudfoundry.com"], "users": ["crichardson@vmware.com"], "version": "56892923b974db90a8f6c7120b665fb17cff7edb-1", "start": "2011-12-02 23:06:01 +0000", "runtime": "java", "state_timestamp": 1322867161, "port": 40198, "limits": { "fds": 256, "mem": 536870912, "disk": 2147483648 }, "host": "172.30.50.9"
  56. 56. VCAP_SERVICES { "mysql-5.1": [{ "name": "mysql1", "label": "mysql-5.1", "plan": "free", "tags": ["mysql", "mysql-5.1", "relational"], "credentials": { "name": "d7cb8afb52f084f3d9bdc269e7d99ab50", "hostname": "172.30.48.20", "host": "172.30.48.20", "port": 3306, "user": "usmMRfwzyYG53", "username": "usmMRfwzyYG53", "password": "pxWSBVeu80GDp" } }]
  57. 57. CloudEnvironment: parses JSON so you dont have toCloudEnvironment env = new CloudEnvironment();Properties props = env.getCloudProperties();String prop = props.getProperty( "cloud.services.mysql1.connection.hostname" );ApplicationInstanceInfo instanceInfo = env.getInstanceInfo();int port = instanceInfo.getPort();List<String> urls = instanceInfo.getUris();…
  58. 58. Provides access to ServiceInfo…RdbmsServiceInfo mis = env.getServiceInfo(! ! "mysql1",! ! RdbmsServiceInfo.class);String mySqlUrl = mis.getUrl();
  59. 59. … which can create DataSources etc@Configurationpublic class CloudDataSourceConfiguration { @Bean public DataSource dataSource() { CloudEnvironment environment = new CloudEnvironment(); RdbmsServiceInfo mysqlSvc =! ! environment.getServiceInfo("mysql1", RdbmsServiceInfo.class);! RdbmsServiceCreator dataSourceCreator = new RdbmsServiceCreator(); DataSource dataSource = dataSourceCreator.createService(mysqlSvc); return dataSource; }} 59
  60. 60. <cloud:*/> namespace  Spring XML namespace  Defines beans from CloudEnvironment • Connection factories, e.g. DataSource • Properties
  61. 61. <cloud:data-source/> Configures a JDBC DataSource <cloud:data-source id="dataSource" service-name="mysql1"> <cloud:pool pool-size="1-5"/> <cloud:connection properties="charset=utf-8"/> </cloud:data-source> ... @Autowired private DataSource dataSource ; 61
  62. 62. <cloud:properties>  Exposes basic information about services that can be consumed with Spring’s property placeholder support  Properties automatically available when deploying Spring 3.1 applications<cloud:properties id="cloudProperties" /><context:property-placeholder properties-ref="cloudProperties"/>class SomeClass {@Value("${cloud.services.mysql1.connection.hostname}")private String mysqlHost; 62
  63. 63. Configuring Cloud Foundry apps is easy BUT How to run on the desktop too?
  64. 64. Isolating Cloud Foundry configuration Use Spring 3.1 profiles Beans belong to one or more profiles At runtime, one or active profiles active beans By default, default profile is active Activate profiles using • system property: -Dspring.active.profiles=profile1,profile2 • programmatically
  65. 65. Using <beans profile=""/><bean class="org.sf.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/></bean> Outside of Cloud Foundry<beans profile="default"> <bean class="org.a.commons.dbcp.BasicDataSource" id="dataSource"> <property name="url" value="jdbc:mysql://localhost/my_db" /> </bean></beans> Inside Cloud Foundry<beans profile="cloud"> <cloud:data-source id="dataSource" /></beans> Profiles available in Spring 3.1 65
  66. 66. Using @Profile@Configuration@Profile("default")public class LocalDataSourceConfiguration { @Configuration @Bean @Profile("cloud") public DataSource dataSource() { public class CloudDataSourceConfiguration { } @Bean public DataSource dataSource() {} ! ! … } } 66
  67. 67. Application configuration via environment variables $ vmc env-add cf1 PAYMENT_SVC=http://... Adding Environment Variable [PAYMENT_SVC=http://...]: OK Stopping Application: OK Staging Application: OK String value = System.getenv("PAYMENT_SVC") @Value("#{systemEnvironment[PAYMENT_SVC]}") private String envVariable;
  68. 68. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases • Why NoSQL? • Using MongoDB • Cloud Foundry and MongoDB Cloud Foundry and asynchronous architectures
  69. 69. Cloud Foundry provides NoSQL-aaS But what’s a NoSQL database? Why would you want to use it? How do you use it? 69
  70. 70. Solution: Use NoSQL Benefits• Higher performance• Higher scalability• Richer data-model• Schema-less Drawbacks • Limited transactions • Relaxed consistency • Unconstrained data 70
  71. 71. Future = multi-paradigm data storage for enterprise applications e.g. Netflix • RDBMS • SimpleDB • Cassandra • Hadoop/Hbase IEEE Software Sept/October 2010 - Debasish Ghosh / Twitter @debasishg 71
  72. 72. Spring Data is here to help For NoSQL databases http://www.springsource.org/spring-data 72
  73. 73. What you get Template classes that hide the boilerplate code, similar to JdbcTemplate Auto-generated (generic) repositories Java NoSQL mapping Cross Store Persistence Support in Roo and Grails 73
  74. 74. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases • Why NoSQL? • Using MongoDB • Cloud Foundry and MongoDB Cloud Foundry and asynchronous architectures
  75. 75. MongoDB Document-oriented database • JSON-style documents: Lists, Maps, primitives • Schema-less Transaction = update of a single document Rich query language for dynamic queries Very fast Writes are asynchronous! Highly scalable and available 75
  76. 76. Data model = Binary JSON documents Server Database: Food To Go Collection: Restaurants { "name" : "Sahn Maru", "type" : ”Korean", "serviceArea" : [ "94619", "94618" ], "openingHours" : [ { "dayOfWeek" : "Wednesday", Sequence of "open" : 1730, bytes on disk "close" : 2230 }  fast i/o ], "_id" : ObjectId("4bddc2f49d1505567c6220a0") } 76
  77. 77. MongoDB use cases Use cases • High volume writes • Complex data • Semi-structured data Who is using it? • Shutterfly, Foursquare • Bit.ly Intuit • SourceForge, NY Times • GILT Groupe, Evite, • SugarCRM 77
  78. 78. MongoTemplateSimplifies data access MongoTemplate POJO  DBObjectTranslates exceptions databaseName mapping userId Password defaultCollectionName writeConcern writeResultChecking save() <<interface>> insert() MongoConvertor remove() updateFirst() write(Object, DBObject) findOne() read(Class, DBObject) find() … uses Mongo MongoMapping (Java Driver class) Converter 78
  79. 79. Example entitypublic class Restaurant { private String id; private String name; private List<MenuItem> menuItems;public Restaurant() {} public class MenuItem {public Restaurant(String name) { private String name; this.name = name; private double price; …} public MenuItem() { }public String getName() { return name; } public MenuItem(String name,public void setName(String name) { double price) { this.name = name; this.name = name;} this.price = price; }…getters and setters… …getters and setters… 79
  80. 80. Example data access code@Repositorypublic class RestaurantRepository { @Autowired private MongoTemplate mongoTemplate; public static final String RESTAURANTS_COLLECTION = "restaurants"; public void add(Restaurant restaurant) { mongoTemplate.save(RESTAURANTS_COLLECTION, restaurant); } public List<Restaurant> findRestaurantsByName(String restaurantName) { return mongoTemplate.find(RESTAURANTS_COLLECTION, new Query(where("name").is(restaurantName)), Restaurant.class); } 80
  81. 81. Mongo document{ "_id" : ObjectId("4d977f55d3fe3119c904e026"), "menuItems" : [ { "name" : "Tandoori Portobello Mushrooms", "price" : 5.5 }, { "name" : "Duck Curry Kerala", "price" : 15 } ], "name" : "Ajanta"} 81
  82. 82. MongoDB bean definitions 82
  83. 83. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases • Why NoSQL? • Using MongoDB • Cloud Foundry and MongoDB Cloud Foundry and asynchronous architectures
  84. 84. Using Mongo and Redis with Cloud Foundry Create a service - Mongo or Redis Bind it to your application Use <cloud:*/> namespace to access the bound service • when cloud profile is active 84
  85. 85. Deploying a Mongo application 85
  86. 86. Using the Mongo Application 86
  87. 87. NoSQL and Caldecott Caldecott let’s you tunnel to a NoSQL service Use Redis CLI • redis-cli • Explore database, adhoc operations • ... Use Mongo CLI etc • Explore database, adhoc operations • Mongo dump/restore • ... 87
  88. 88. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures • Why use messages? • RabbitMQ and Spring AMQP • Using Spring Integration • Using RabbitMQ on Cloud Foundry
  89. 89. Cloud Foundry provides RabbitMQ - aaSBut what’s RabbitMQ?Why would you want to use it?How do you use it? 89
  90. 90. But why messaging? Why RabbitMQ? Application A Application B RabbitMQ Traditional application integration 90
  91. 91. Messaging within applications wgrus-billing.war Accounting Service wgrus-inventory.war wgrus-store.war Widget Message InventoryService StoreFront Broker MySQL wgrus-inventory.war Gadget InventoryService Decouples front-end from back-end Front-end continues to work wgrus-shipping.war when back-end is down Shipping Broker smoothes out traffic Service spikes 91
  92. 92. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures • Why use messages? • RabbitMQ and Spring AMQP • Using Spring Integration • Using RabbitMQ on Cloud Foundry
  93. 93. RabbitMQ – Messaging that Just Works Robust High-performance Easy to use AMQP LEADER
  94. 94. Why AMQP? A  Protocol,  not  an  API •A defined set of messaging capabilities called the AMQ model •A network wire-level protocol, AMQP On  commodity  hardware •10-­‐25  thousand  messages  per   second  is  rou7ne  * •The  NIC  is  usually  the   boIleneck *  Non-­‐persistent  messages17
  95. 95. Spring AMQP Encapsulates low-level details Producer Consumer Simplifies sending and receiving of messages Amqp Listener Template Container Spring AMQP AMQP
  96. 96. Sending AMQP messages@Component public class MessageSender {@Autowiredprivate volatile AmqpTemplate amqpTemplate;public void send(String message) { this.amqpTemplate.convertAndSend( "myExchange", "some.routing.key", message);}public void read() throws Exception { ... String value = amqpTemplate.receiveAndConvert("myQueueName"); ... } 96
  97. 97. Spring AMQP is flexible and dynamic BUT It’s very low level 97
  98. 98. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures • Why use messages? • RabbitMQ and Spring AMQP • Using Spring Integration • Using RabbitMQ on Cloud Foundry
  99. 99. Spring Integration Builds on Spring framework High-level of abstraction for building message based applications Implements EAI patterns Provides plumbing for exchanging messages between application components Promotes loosely coupled components Integrates with external messaging infrastructure: JMS, AMQP, HTTP, Email, File transfer 99
  100. 100. 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 • Outbound channel adapter - read from channel write to external destination 100
  101. 101. Using Spring Integration with the web store application 101
  102. 102. wgrus-store.war wgrus-shipping.war StoreFront Shipping Service Spring Integration RabbitMQ Spring Integrationwgrus-billing.war wgrus-inventory.war Credit Service Spring Integration Widget InventoryService Gadget InventoryService 102
  103. 103. Store front flowStoreUI object to Message Endpoint orderChannel amqpOut AMQP JSON 103
  104. 104. 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 104
  105. 105. Shipping flow shipping service Json to AMQP shipping Service Object order Activator channel 105
  106. 106. Agenda Why PaaS? Cloud Foundry basics Using Cloud Foundry services Spring and Cloud Foundry Using NoSQL databases Cloud Foundry and asynchronous architectures • Why use messages? • RabbitMQ and Spring AMQP • Using Spring Integration • Using RabbitMQ on Cloud Foundry
  107. 107. Rabbit on Cloud Foundry 107
  108. 108. Configuring a ConnectionFactory<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/><beans profile="default"> ... <rabbit:connection-factory id="rabbitConnectionFactory"/></beans><beans profile="cloud"> ... <cloud:rabbit-connection-factory id="rabbitConnectionFactory"/></beans> 108
  109. 109. Using Caldecott with RabbitMQ Use for JUnit/Integration tests Run RabbitMQ tools xxxxx xxxxx xxxxx 109
  110. 110. Summary PaaS? Good. Cloud Foundry? Good. Spring? Good. Cloud Foundry and Spring? Really good! Home work: • Learn Spring: http://www.springframework.org • Learn Spring Data http://www.springframework.org/spring-data • sign up for (free) Cloud Foundry at http://www.cloudfoundry.com • Download the Cloud Foundry Micro Cloud 110
  111. 111. @cloudfoundry @crichardson chris.richardson@springsource.com Questions? www.cloudfoundry.com promo code EgyptJUG

×