We just released an update for Micro Cloud Foundry with PostgreSQL and RabbitMQ. Micro Cloud Foundryis a complete version of Cloud Foundry that runs in a virtual machine on a developer’s Mac or PC. Today, vFabric Postgres, a version of PostgresSQL database optimized for the virtualized cloud environment, and RabbitMQ, a reliable, scalable and portable messaging system, are both available with Micro Cloud Foundry.
Developers can now quickly develop and test applications with RabbitMQ as its messaging solution and/or PostgresSQL as its data store solution, on their local machine before deploying and scaling to the cloud.
vFabric Postgres and RabbitMQ are available as part of a new update for Micro Cloud Foundry, available for download today at http://micro.cloudfoundry.com
In the following blog post, we will walk through two simple examples of how to run a Java Spring application using Postgres and a Spring AMQP calculation demo using RabbitMQ on your Micro Cloud Foundry.
First, you will need a CloudFoundry.com account, if you don’t have one yet, please signup here.
Next, you will need to download the new update for Micro Cloud Foundry (version “1.1”)
Login to Micro Cloud Foundry (using your CloudFoundry.com credentials) and download the new “micro-1.1.0” VM.
You will also need to create/ regenerate your domain token.
Please note that you cannot upgrade from the previous version of Micro Cloud Foundry to the new one. For more information on getting started with Micro Cloud Foundry, please read the following blog post.
Postgres andMicro Cloud Foundry
Postgres on Micro Cloud Foundry enables developers to build, test and deploy applications on their laptop while leveraging a robust and reliable PostgreSQL relational database. As Micro Cloud Foundry and CloudFoundry.com both include the vFabric Postgres service, the same application can be deployed on CloudFoundry.com without any code changes while leveragingincreased database capacity.
Once you have the updated Micro Cloud Foundry installed, you can check the status of Postgres using option 7 in the menu.
Steps to create a Java Spring App using Postgres
Now lets look at steps to create and run a Guestbook application on Micro Cloud Foundry, then deploy to Cloud Foundry. For detailed instructions and code for writing the Spring app (steps 1-8), please see the support article
1. Create a Maven Web Project
2. Add dependency on the Spring framework and automatically download all required java package from Maven repository using pom.xml
3. Define entity class to store objects in a database using JPA
4. Configure JPA by setting a META-INF/persistence.xml file
5. Define a Spring DAO Component: Operations on the database will be performed by an instance of a Data Access Object (DAO) that we will define in this step as a Spring MVC
6. Add a Spring Controller Class to manage guestbook web requests
7. Add a JSP page
8. Integrate the Spring Framework into the web application by adding the definition of the Spring dispatcher servlet to the web.xml configuration file and configuring that servlet using another xml configuration file.
The settings above guides Spring to support annotations (for components, controllers and transactions), to inject a JPA EntityManager, to manage transactions and to look for JSP pages in the WEB-INF directory.
9. Build the project and deploy to Micro Cloud Foundry
Open a command prompt (Windows) or terminal (Linux) and “cd” to the location of the Guest project in the Eclipse workspace. Type command “mvn package” to generate war file Guestbook.war
$mvn package [...] [INFO] --------------------------- [INFO] BUILD SUCCESSFUL [INFO] --------------------------- [INFO] Total time: 3 seconds [INFO] Finished at: Mon Aug 08 23:59:32 GMT-08:00 2011 [INFO] Final Memory: 31M/428M [INFO] ---------------------------
Now we are ready to push the application to Micro Cloud Foundry. Change to the target directory before doing vmc push. Here, we will call the application “‘guestbook”
$vmc push Would you like to deploy from the current directory? [Yn]: y Application Name: guestbook Application Deployed URL: 'guestbook.yourcloud.cloudfoundry.me'? Detected a Java SpringSource Spring Application, is this correct? [Yn]: y Memory Reservation [Default:512M] (64M, 128M, 256M or 512M) Creating Application: OK Would you like to bind any services to 'guestbook'? [yN]: y Would you like to use an existing provisioned service [yN]? n The following system services are available:: 1. mongodb 2. mysql 3. postgresql 4. redis Please select one you wish to provision: 3 Specify the name of the service [postgresql-9a305]: guestbook Creating Service: OK Binding Service: OK Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (9M): OK Push Status: OK Staging Application: OK Starting Application: OK
Now your application is running inside the Micro Cloud Foundry! Use “vmc services”, “vmc apps” commands to retrieve service and application information.
Go to http://guestbook.yourcloud.cloudfoundry.me and see the web page:
Type anything you want and click on “Add’, what you just type will appear in the page, stored in your local PostgreSQL database.
Deploy to CloudFoundry.com with zero change
Now it’s time to deploy this application to CloudFoundry.com public PaaS service and see how the application works without any change in code and configuration!
First, use vmc target command to point to Cloud Foundry:
$vmc target api.cloudfoundry.com Successfully targeted to [ http://api.cloudfoundry.com] $vmc login Email: [Your Cloud Foundry email] Password: [Your Cloud Foundry password] Successfully logged into [ http://api.cloudfoundry.com]
Use the same vmc push command used above to deploy the application:
$vmc push Would you like to deploy from the current directory? [Yn]: y Application Name: guestbook-mycloud Application Deployed URL: 'guestbook-mycloud.cloudfoundry.com'? Detected a Java SpringSource Spring Application, is this correct? [Yn]: y Memory Reservation [Default:512M] (64M, 128M, 256M or 512M) Creating Application: OK Would you like to bind any services to 'guestbook-postgresql'? [yN]: y Would you like to use an existing provisioned service [yN]? n The following system services are available:: 1. mongodb 2. mysql 3. postgresql 4. rabbitmq 5. redis Please select one you wish to provision: 3 Specify the name of the service [postgresql-a9x55]: guestbook Creating Service: OK Binding Service: OK Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (9M): OK Push Status: OK Staging Application: OK Starting Application: OK
The application behaves exactly the same as in Micro Cloud Foundry, and stores input data into the Postgres database instance running on CloudFoundry.com.
RabbitMQ and Micro Cloud Foundry
RabbitMQ on Micro Cloud Foundry enables developers to build, test and deploy applications on their laptop while leveraging a reliable, scalable and portable RabbitMQ messaging system, without the need to set up Rabbit locally.
As Micro Cloud Foundry and CloudFoundry.com both includeRabbitMQ, the same application can be scaled up on CloudFoundry.com without any code changes: just use the vmc command line to add workers.
See above for how to download and configure Micro Cloud Foundry 1.1. Once you have done that, if you press 7 in the Micro Cloud Foundry console, to get the service status, you will see the RabbitMQ services listed.
The Spring AMQP Π Calculation Demo for CloudFoundry sample works out of the box on your local machine: it is an adaptation of Jonas Boner’s excellent Akka Getting Started Tutorial that calculates the value of Π but using RabbitMQ worker queues instead of Actors.
It relies on the Leibniz formula for Π, which has the advantage of lending itself to easy parallelization:
In the sample, you use a picalc-master application that creates n tasks in Rabbit, and p instances of the picalc-worker application that pull the calculations tasks from a Rabbit queue and push results there, to be accumulated by the master.
This is what it looks like on a recent MacBook Pro with n=5000 and p=3.
Simply follow the instructions in the README, targeting vmc and your browser to yourcloud.cloudfoundry.com, if you are using DynDNS, or vcap.me if you have configured Micro Cloud Foundry to work offline.
One aspect that is different when working locally vs in the cloud is that the local VM has a limited amount of RAM, so the number of worker instances you can launch locally is limited. You may want to try out the sample with 2 or 3 workers instead of 4, because currently Micro Cloud Foundry does not use more than 1Gb RAM, even if you configure the VM with more capacity.
With the new release of Micro Cloud Foundry, you can try out your Cloud Foundry applications on your laptop, without having to install your Postgres or RabbitMQ Cloud Foundry services.
If you have any questions or problems, please contact us at http://support.cloudfoundry.com
– The Cloud Foundry Team
Don’t have a Cloud Foundry account yet? Signup for free today
About the Author