Heroku Neo4j, App Harbor MVC4, Neo4jClient & Ruby Proxy

Overview

We going to outlay the process to deploy a 4 layers architecture using the above technologies.

architecture

Prerequisites

Sinatra and Rest-Client

Sinatra and the Rest-Client libraries are used in the Ruby Gem to proxy all Http requests to Neo4j.

Install Process

Install the Heroku client, run this from the heroku\Ruby\bin folder e.g. D:\Program Files (x86)\Heroku\ruby\bin

gem install heroku

We then need to use the Cedar stack (http://devcenter.heroku.com/articles/cedar) which supports ruby in Heroku,  so run:

heroku create –stack cedar

(Ensure git.exe is in your environment variables)

image

Once this is completed we then deploy our code to our Heroku git repository. You can see your git heroku repository in the app details for the app you created in Heroku:

image

We will use a public key that we created when first setting up Heroku, check blog post

https://romikoderbynew.com/2012/01/25/getting-started-with-heroku-toolbelt-on-windows-2/

if you changed your public key, then add it to Heroku

heroku keys:add

Ok, now we push the Gem files to our Heroku git repository. Your repsotory will be different to mine!

git push git@heroku.com:neo4jorbust.git master

image

Lets check the state of the application

E:\Projects\RubyRestProxy>heroku ps –app neo4jorbust
Process State Command
——- ———– ————————————
web.1 idle for 9h thin -p $PORT -e $RACK_ENV -R $HER..

Test HttpClient –> Ruby –> Neo4j Communication

Nice, now we got this GEM file, which is our Ruby http proxy code for gremlin queries. Lets test this baby out with fiddler and run  gremlin query to the web app, which will then call neo4j!

Lets browse the Ruby Application on the Heroku server, so we can find out what URL we need to use to send Gremlin queries to Neo4j.

image

Beautiful, all we need to do now is send an HTTP POST to the added, you can use curl, but here is fiddler.

image

And the result, music to our eyes

image

ASP.NET MVC 4 APP with Neo4jClient

This application is hosted at

http://frictionfree.org

Source Code:

https://bitbucket.org/romiko/frictionfree/src

Now we going to fire up a .Net application that will use the Neo4jClient Rest Api to communicate with neo4j in Heroku. You can find out more about Neo4jClient here http://hg.readify.net/neo4jclient/wiki/Home

Clone the git repository to get the source code for our sample Neo4jClient .Net application. This is a MVC4 application and runs on the .Net Framework 4 runtime, so please ensure you have this installed on your windows machine.

About frictionfree.org

The application is used to find other people with similar interests to you and the opportunity to get their details and contact them to perhaps share your love of flying, surfing or whatever it is you like to do!

Bitbucket and AppHarbor integration

If you have your own ASP.NET application, you can store it in bitbucket and then configure bitbucket to auto deploy to AppHarbor when pushing back the repostory.

In the admin settings for your repository just add your appharbor token.

image

Neo4jClient gremlin Query syntax

Check the source code of the MVC application in the Logic library to see how to run queries to Neo4j. Here is sample code to get administrators of the system

private void CreateAdminAccountIfNoneExist() { var anyAdmins = graphClient .RootNode .In(Administers.TypeKey) .Any(); if (!anyAdmins) { provisionNewUserService.CreateAdmin(); } } 
Advertisement

5 thoughts on “Heroku Neo4j, App Harbor MVC4, Neo4jClient & Ruby Proxy

  1. Hey can you explain the Ruby Proxy layer? I understand it’s supposed to support CRUD operations via Gremlin but doesn’t Neo4j already support Gremlin?

    1. The proxy is used so we do not expose the REST API directly. Yes all rest is supported, however the solution I did is a fun project to show cross cloud PAAS communication 😉

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s