Sunday, March 4, 2012

Getting started with the Grails + Neo4j plugin + Heroku

As promised in a previous post, here is a brief update with the Grails Neo4j 1.0.0.M2 plugin. 

This largely follows the guide at http://devcenter.heroku.com/articles/grails

Create the grails app
>grails create-app heroku-neo4j
>cd heroku-neo4j

Check into Git
Create a .gitignore file for ignored files and check into git
*.iws
*Db.properties
*Db.script
.settings
.classpath
.project
eclipse
stacktrace.log
target
/plugins
/web-app/plugins
/web-app/WEB-INF/classes
web-app/WEB-INF/tld/c.tld
web-app/WEB-INF/tld/fmt.tld


>git init
>git add .
>git commit -m init

Create a Heroku app
>heroku create --stack cedar

...and deploy
>git push heroku master

Check it out in the browser
>heroku open

Add the Neo4J addon
>heroku addons:add neo4j:test

Install the Grails Neo4j plugin
>grails install-plugin neo4j

Update BuildConfig.groovy
Add the neo4j repo,
repositories {
    ...
    mavenRepo 'http://m2.neo4j.org/releases'
}



and a compile dependency,
dependencies {
     ...
     compile "org.neo4j:neo4j-rest-graphdb:1.6"
}





Update DataSource.groovy
Configure your database location through DataSource. Since the Heroku Neo4j addon is only accessible via REST, we use type="rest". On Heroku, the system environment variable NEO4J_REST_URL will be set to your own Neo4j instance  


development {
    grails {
        neo4j {
            type = "rest"
            location = "http://localhost:7474/db/data/"
        }
    }
}


production {
    grails {
        neo4j {
            type = "rest"
            location = System.getenv('NEO4J_REST_URL') ?: "http://localhost:7474/db/data/"
        }
    }
}

Now you should be able to use GORM to maintain your Neo4J datastore. 
What's great with this setup is, you can switch to an embedded or HA data setup by modifying the type and location parameters in DataSource, without changing any other code.


One more thing...
Relationship properties are not yet supported. See https://groups.google.com/d/topic/neo4j/6IiFN_RG19I/discussion 



No comments: