The first thing we need to do when starting to work with fuse ESB is set up our build environment. For this we’ll be using Eclipse, with the FUSE IDE plugin and maven. I’ll also cover downloading and installing Servicemix, and then generating our first FUSE project.
I’ll be using a windows box for the majority of this tutorial, but it should be fairly straightforward to get this working on your favoured flavour of *nix if you’re so inclined.
There’s a lot to get through here so lets get started.
Download the latest version of maven from here: http://maven.apache.org/download.html
Extract the downloaded zip somewhere sensible (I use c:\program files\maven)
To make sure we can use maven from the command line we need to add it to our ‘Path’ environment variable. On windows 7 you can do this by right clicking ‘Computer’, selecting ‘advanced system properties’ then click the ‘environment variables’ button. Once the box opens scroll down until you find ‘Path’ under system variables, click edit and add ‘c:\program files\maven\bin’ to your string.
That’s maven setup, lets move onto something a little more challenging.
Before we can install our FUSE products we need to grab the Java Development Kit (JDK) and ensure that Eclipse and servicemix know where to find it by setting our ‘JAVA_HOME’ environment variable.
grab the JDK from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html and run the installer.
Once it’s installed you need to go back into the ‘Environment variables’ box we were in during the Maven installation and add a new variable called ‘JAVA_HOME’ pointing at the Directory your just installed the JDK into (by default it should be something like ‘C:\Program Files\Java\jdk1.6.0_25′).
Download Eclipse Helios from here: http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr2
Personally I’ve had no problems using the later ‘Indigo’ version of eclipse, but FUSE recommend Helios for working with their IDE so we’ll stick with that. Run the installer as usual. Once it’s installed we need to get the FUSE IDE plugin.
Go here: http://fusesource.com/products/fuse-ide/ to download it. You need to register as part of the ‘Fuse community’, then add the update site listed on that page to your eclipse installation to add the IDE plugin.
Once that’s done the final part of the Eclipse installation is to make Eclipse use our previously installed maven repository rather than the one that comes bundled with Eclipse. In the Eclipse main menu open ‘Window’->’Preferences’. Then select ‘Maven’->’Installations’. Click ‘Add’ and browse to your maven directory (in my case it’s ‘c:\program files\maven’). Click OK and you’re done.
For our ServiceMix installation I’m going to use the packages provided by FuseSource as ‘Fuse ESB#. You can get the latest version from here: http://fusesource.com/products/enterprise-servicemix/.
Download the latest Zip file and extract it somewhere obvious (c:\servicemix for example).
And…that’s pretty much it, you should now be able to start Servicemix from the command line by changing to the servicemix directory and running the command ‘bin\servicemix.bat‘. If everything goes well you should see something like this:
Generating our first project
Now everything’s setup lets try generating and deploying a simple test project.
To generate our project structure we can use the maven archetype generator as follows:
First create a new, empty directory where we’ll be working (I’m using c:\testproject)
Next run the command ‘mvn archetype:generate‘. this will prompt maven to download the latest list of archetypes and display them as a huge list. Luckily we can filter this list if we know the name of the archetype we want. Type ‘karaf-blueprint-archetype‘ to return our filtered list, which should have 1 entry. press 1 to select this entry and then from the list of versions that follows select the latest one (at time of writing this is 2.2.7).
You’ll now be prompted for some information about the project, use the following (or replace with your own values as required):
Once you’ve entered the details a simple ‘Y’ will confirm them and generate our project.
Import project into eclipse
The next stage is to import our project into Eclipse. In the Eclipse main menu select ‘File’->’Import’, then from the import box scroll down and select ‘Maven’->’Existing Maven Projects’.
In the Import window browse to the location of your test project (notice maven has generated it in a subdirectory of our root directory) as shown:
Click ‘Finish’ to import the project. You may get a ‘NullPointerException’ here for some reason, but the project should still import.
Configure a ‘Hello World’ Route
Now let’s make our project actually do something.
If you open up your project structure, you should see something like this:
There’s a few files and folders here to take note of, and we’ll go into these in more detail in further installments of this series, but for now let’s just jump in and start hacking around.
First of all we can remove the sample java beans that Maven gives us, so delete the two files under your java class path. In my case this is ‘test-project\src\main\java\uk\co\tall-paul’.
We can also get rid of the sample camel context (in the file ‘my-service.xml’) and replace it with our own. So remove that file and create a new one in the same place called ‘hello-world.xml’ containing the following:
<camelContext id="hello-world-context" xmlns="http://camel.apache.org/schema/blueprint">
<log message="hello world!"/>
For more info on what that xml actually does have a look at the camel website, and specifically the information abou the various components which you can find here: http://camel.apache.org/components.html
This simple route basically uses a timer to fire off a message every 5 seconds, then logs ‘hello world’ to the console.
Build the Project
To build the project we can run maven from the command line or from within eclipse.
From the command line, navigate to the project folder (c:\testproject\test-project) and run the command ‘mvn clean install‘ (you can find more information about various maven commands here: http://maven.apache.org/maven-1.x/reference/command-line.html , but really ‘mvn clean install’ is all you’ll need for now). If all goes well you should (eventually) see something like the following:
From Eclipse you can do pretty much the same thing by right clicking on your project and selecting ‘Run as’->’Maven install’ as shown here:
Our project has now been compiled and installed into our maven repository, which you can see if you browse to the location of the repository (by default this is at c:\users\YOURUSERNAME\.m2\repository):
Deploy the project into servicemix
Thanks to the integration of maven into servicemix, deploying our project is trivial using the ‘install’ command withing servicemix.
From your servicemix consolerun the following command:
Hopefully you should be given a bundle ID, something like ‘bundle ID: 200′. Now type the following command (substituting the bundle ID you were given for the 200 shown here)
And that should be it. As long as you didn’t see any error messages, your bundle should now be running. To see the output from our route type the following commands (the first clears the log file for clarity, the second displays the current log)
after a few seconds you should see something like this:
You can see that every 5 seconds our timer is going off and logging our message to the console. You can also see here the name of the component the message originated from (remember we put ‘test’ as the first parameter for our timer component) and the route in which the message is running (here it’s ‘hello-world=route’), which indicates the importance of naming your routes and components sensibly.
Hopefully this brief tutorial has shown how easy it is to get up and running with Fuse ESB development. Next time we’ll look at how to use the environment we’ve set up here to do some real integration work.