Wednesday, 10 August 2011

Grails + RabbitMQ + Cloud Foundry: Messaging in Cloud Foundry

Now that the RabbitMQ service is publicly live on cloudfoundry.com, the question I asked myself was how hard would it be to deploy the application I described in “Grails + RabbitMQ: Sending a JSON Message” onto Cloud Foundry?

Grails Plugin for Cloud Foundry
In my blog ‘Grails + SQLFire + MySQL: Deploying to Cloud Foundry’ I described the installation and usage of the Cloud Foundry command line tool ‘VMC’. VMC is a great tool however I recently discovered a Grails Cloud Foundry plugin that allows me to execute Cloud Foundry commands from within the Grails console.

To install the Grails Cloud Foundry plugin simply do:

install-plugin cloud-foundry

Login Details
The Grails Cloud Foundry plugin looks for login credentials in Config.groovy. To configure the credentials, open Config.grooy and add the following properties:

grails.plugin.cloudfoundry.username='[your email]'
grails.plugin.cloudfoundry.password='[your password]'

Creating a Cloud Foundry Services
I am going to use the application from “Grails + RabbitMQ: Sending a JSON Message”. This application needs both RabbitMQ and MySQL.  To achieve this, the first thing we need to do is create instances of both RabbitMQ and MySQL service against your account account.

Open the Grails console and execute:

cf-create-service rabbitmq rabbitmq
cf-create-service mysql mysql

Pushing to Cloud Foundry
Lets attempt to push the example project “Grails + RabbitMQ: Sending a JSON Message” to Cloud Foundry. Open the Grails console within your example project and execute:

cf-push

This command packages up your application and kicks off the process of uploading you application to Cloud Foundry. As part of the process, the command is going to ask you a series of simple questions:

Q1: You running in development …etc? - Basically Grails is asking if it should build the war.   
A: ‘y’

Q2: Application Deployment URL?
A: Enter the URL you would like to deploy this application on.

Q3: Would you like to bind ‘mysql’?
A: ‘y’

Q4: Would you like to bind ‘rabbitmq’?
A: ‘y’

It really is that simple.

Testing
Open a web browser and hit the URL you entered during the push process. 

Enjoy :-) 

1 comment:

  1. Hi Chris,

    Just a quickie: I recommend putting your Cloud Foundry credentials in ~/.grails/settings.groovy since this file doesn't go into source control. Also, it's loaded by all projects.

    Glad to hear it works so smoothly!

    Peter

    ReplyDelete