Creating a Hello World JBI Binding Component
This tutorial describes how to create a very simple Hello World style of JBI binding component. This tutorial is as minimalistic as possible so as to focus on key concepts and not drown in details. The Hello World binding component will respond to all requests with the message:
...
The following sections will walk through the creation, packaging, testing and deployment of the Hello World binding component.
Prerequisites
- Maven 2.0.4 or higher
- If you have never used Maven previously the Maven Getting Started Guide explains some valuable concepts surrounding Maven
- ServiceMix 3.1-incubating-SNAPSHOT or higher
- See the ServiceMix downloads to grab a nightly build as ServiceMix 3.1 has not yet been released
- A broadband internet connection so Maven can automatically download dependencies
A Very Brief Introduction to Java Business Integration
The Java Business Integration (JBI) spec provides a standards-based, service-oriented approach to application integration through the use of an abstract messaging model, without reference to a particular protocol or wire encoding. JBI introduces the concepts of Binding Components (BCs), Service Engines (SEs) to Service Units (SUs) and Service Assemblies (SAs) to define an architecture for vendor-neutral pluggable components. The purpose of this architecture is to provide standards-based interoperability amongst components/services.
...
Now let's move on to creating the Maven projects for the Hello World binding component.
Creating a Maven Project For the JBI BC
The focus of this section is on the creation of a JBI binding component. For this task, a Maven archetype will be used to create a Maven project skeleton to house the component. Maven archetypes are templates for Maven projects that jumpstart project creation via the automation of repetitive tasks by following standard conventions. The result of using an archetype to create a Maven project is a directory structure, a Maven POM file and, depending on the archetype being used, sometimes Java objects and JUnit tests.
...
Note | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||
The maven-archetype-plugin 1.0-alpha4 or above is required for this tutorial. When an older version is installed, a build error will occur. The version of this plugin can be checked by verifying the name of the following directories:
In case the only version available of the maven-archetype-plugin is an older one, a minimal
|
Compiling the Project
Since we just created this project, we should first compile it just to make sure nothing is wrong with what the archetype generated. To compile, package and test the project, execute the following command from the command-line:
...
Again, the key here is to make sure you see BUILD SUCCESSFUL. This means that the project skeleton created by the archetype was compiled, packaged and tested successfully. Now we just need to add some custom functionality.
Creating the JBI Component
Before we create any custom functionality, let's first examine some of the items generated by the servicemix-service-engine Maven archetype in this simple component we're developing. These classes extend class from either the JBI spec APIs or from the servicemix-common
package.
...
Now that we've gotten a bird's eye view of what we're working with, let's proceed to adding the custom functionality.
Adding Custom Functionality
Note | ||
---|---|---|
| ||
It is at this stage that you should employ the use of an IDE. An IDE can dramatically reduce the work necessary to import clases, override methods and so much more. Because Maven can generate project files for Eclipse and IntelliJ IDEA, either one can be used. Throughout this tutorial, Eclipse will be used. To generate project files for Eclipse, execute the Maven |
This is a work in progress. I will finish this up very soon.
Testing the Hello World Binding Component
Thanks to the archetype, testing the component is very easy because it already created a test. The only change we'll make is to the string being sent by the client code. In the src/test/java
directory is the org.apache.servicemix.samples.helloworld.bc.MySpringComponentTest
test. Simply open this test and change line #36 from this:
...
Wiki Markup |
---|
Notice that not only do we see that the build was successful, but also note the text in the output above that was printed by the test (*<hello>Hello World! Message \[<hello>Ski Colorado!</hello>\] contains \[28\] bytes.</hello>*). This is the message we were expecting to be output from the test. So if you see this, you just wrote a JBI component and tested it successfully. Now this SU needs to be wrapped in a SA so it can be deployed to the JBI container. |
Wrapping the Service Unit in a Service Assembly
The component we created above and packaged as a SU cannot be directly deployed to a JBI container until it's wrapped in a SA. This can be done by creating a SA with a dependency on the SA. From within the hello-world-smx
directory, execute the following commands to create the project for the SA:
...
Code Block |
---|
$ cd hello-world-sa $ mvn install |
No Format |
---|
Incorporating the Projects Into a Top Level POM
Now that we have created the SU and SA projects, a top level pom.xml
must be manually created and made aware of each subproject. This will allow all the projects to be built automatically without having to build each project in order manually. Maven will discover all the projects and build them in the proper order. In the hello-world-bc-su
directory, create a file named pom.xml
containing the following content:
...
As long as you see the BUILD SUCCESSFUL message in the output continue to the next section to give each project a unique name.
Give Each of the Maven Subprojects a Name
Notice in the output above that there are a two projects named A custom project. This is because the archetypes create projects with this generic name. Let's give each project a unique name via each component's pom.xml
file. This name will allow Maven's output to denote a component's name in its output making our development work a bit easier. To name each project, simply edit each pom.xml
and replace <name>A custom project</name>
with an appropriate name. Below are the instructions for naming each component's project:
...
Now when the projects are built you will no longer see a project named A custom project. Instead you'll now see Hello World SE Service Unit and Hello World Service Assembly. Rebuild the projects again using the mvn clean install
command on the command-line to see the change.
Deploying the Component
Now that the SA is built, we're ready to deploy it to the JBI container.
...
Note | ||
---|---|---|
| ||
The default implementation of the component accepts InOut MEPs (ADD OUTLINE for further work:
Classpath for SU to include manually till v3.1, see mail manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units INS When to use this JBI Component provide exact position in the SVN! maybe moving the content of overlapping existing docus to this new tut and - where appropriate - delete the old ones (only leaving a redirect). This shall already include everything stated at provide additional reading |