I’ve mentioned Atom Hopper several times in this blog. Atom Hopper (based on Apache Abdera) for those whom might not know is a Rackspace sponsored open source project. Today I’ll show you how to use the new MongoDB data adapter. Although the MongoDB data adapter has not been fully tested and therefor shouldn’t be used in production yet, as a developer you can kick the tires and send us feedback or pull requests with improvements.
Once testing and refactoring, etc. has been completed for the MongoDB data adapter it will most likely be turned on by default rather than the current Hibernate data adapter. For now I’m going to assume it (MongoDB data adapter) needs to be manually turned on.
Important: Make sure to put an Index on DateLastUpdated – this will greatly improve HTTP GET requests.
As our wiki states there are several ways to run Atom Hopper. To test out the MongoDB adapter with Atom Hopper I’m going to show you how to run it from Netbeans 7.1. You will also need MongoDB running locally on your computer.
Step 1: Get the Source Code
The source code is open sourced under the Apache 2 license. You can use Git to grab the source code easily. I’m on OS X and I tend to use GitHub’s Mac client but you can use the Git functionality in Netbeans as well.
Step 2: Compile the Source Code
Once you have the master repository for Atom Hopper downloaded you can use Netbeans 7.1 to load the project. Start Netbeans if it isn’t running already and choose: File -> Open Project and locate the atom-hopper folder and click on the Open Required Projects option and then click open.
Once you have the project loaded right-click on the ATOM Hopper – ATOMpub Server Collection project and select Clean and Build.
Step 3: Running the stand alone Jetty version (only for testing)
At this point the project should’ve built successfully – and it may take a while since all the dependencies need to be downloaded first. Normally when you run Atom Hopper you use the resulting WAR file and deploy that to something like Apache Tomcat. For simplicity and because this is only to test the new MongoDB adapter for Atom Hopper I’ll simply show you how to run the standalone Jetty version which is what is used to debug Atom Hopper.
Right click on the ATOM Hopper – Default Jetty Server project and select Properties.
In the Project Properties dialog that opens up click on Run in the left hand side categories and then on the right add the word start to the Arguments textbox.
Press the Ok button and return to the project. Go into the ATOM Hopper – Default Jetty Server project files and locate the atom-server.cfg.xml and the application-context.xml files.
Let’s add MongoDB as the default adapter in the application-context.xml file. This is done by commenting out the Hibernate adapter and uncommenting in the MongoDB adapter. The file should look like this:
Now we just need to set the atom-server.cfg.xml file to point to the MongoDB feed publisher and source:
Go ahead and re-compile the ATOM Hopper – Default Jetty Server project, then right-click on it and select Run.
The start command we set earlier allows the Jetty server to startup under the following defaults:
Use the above URL to test everything out. You can perform an HTTP POST or GET to the feed. Here is a sample ATOM XML you can use to test with:
This is the title John Doe Hello World
Before doing an HTTP POST make sure to set the content-type as application/atom+xml. You can get more details on how to use a plugin to test Atom Hopper from here.
To shutdown the Jetty standalone server simply go back into the ATOM Hopper – Default Jetty Server project and then right-click on it and select Properties. In the Project Properties dialog that opens up click on Run in the left hand side categories and then on the right add the word stop to the Arguments textbox. Then run the ATOM Hopper – Default Jetty Server project which will send a shutdown command to the running instance.
A final reminder… The MongoDB data adapter is still going through refactoring and testing so it is not ready for production usage at this time. Follow Atom Hopper on Twitter and you will be the first to know when it has stabilized enough for production usage. See the Atom Hopper wiki for the latest documentation.