You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

 Tutorial: Creation of a "Hello World - SE"

This tutorial describes how to create a very simple "Hello world" JBI service engine (SE) component, pack it into a Service Unit (SU) which will be packed to a Service Assambly (SA), and finally how to run the SE inside ServiceMix. The SE will answer your messages with "Hello, I received xyz bytes!", so you literally see that it works. As it has the same structure as real, useful SE, the given hints help you to use it as a blueprint to create your own SE-SA-SU. Still, the example is as minimalistic as possible, so are not getting lost in too many details and you get an idea of the big picture.

This tutorial shows you the desired/best practices or "clean" way to create a SE-SA-SU using Maven archetypes, so how the workflow shall be (of course, other possibilities exist and may be better suited for certain situations). Furthermore, it will explain the reasons for critical choices and how to required information can be retrieved. Where appropriate, additional reading will be suggested. To make it as easy as possible to follow the descriptions, they contain only the relevant code snippets, while the full code is available in the SVN repository for reference. Please note that the code snippets are fetched directly from the full code in the SVN repository, thus the wiki and the code share always at the same, up to date state. 

Handy Hints

This tutorial is especially useful for ServiceMix beginners.

The Maven Getting Started Guide is a recommended, short reading. It explains most of the Maven related things you will need.

TODO

 

INS When to use this JBI Component
INS Using the component that you created

http://www.servicemix.org/site/notes-on-creating-jbi-component-using-maven2.html
is already fully incorporated, so delete content and point from there to here

provide exact position in the SVN! 
/samples/hello-world-SE-SU-SA/
integrate from SVN source like it is done at Configuration  at http://www.servicemix.org/site/visualisation.html

maybe moving the content of overlapping existing docus to this new tut and - where appropriate - delete the old ones (only leaving a redirect).

provide additional reading

Maybe add testing 

Prerequisites

You need

  • Around 15 minutes of time
  • A running copy of ServiceMix 3.0 and Maven 2.0.4 or higher
  • A connection to the Internet to download dependencies
  • A text editor to alter XML files

Overview SE-SU-SA

JBI components are can be tought of as the "smallest applications" you can access in an ESB. They have a very specific purpose, thus a narrow scope and set of functionallity. Components come in two flavours: Service Engine (SE) and Binding Components (BC).

Components are enriched by metadata (which?) and the whole is packed into a Service Unit (SU) - basically a JAR archive.

Several SUs are packed into a Service Assambly (SA). An SA is a complete "application" consisting of multiple components (reminder: the "smallest appliactions") interacting with each other and thus making up the big "application". 

Further reading: JSR 208 

Creating the SE

First, a JBI component has to be created. Here, we use archetypes, just like shown at Creating a Standard JBI Component and Notes on Creating JBI Component using maven2 and Creating a protocol bridge. The Maven 2 archetypes are a kind of pattern, generic model, blueprint or template, or as Merriam-Webster defines "the original pattern or model of which all things of the same type are representations or copies". Using archetypes, Maven creates the basis for components and so on, thus they spare developers repetetive work and avoid errors like typos etc.

Note: As this text describes how to create a "Hello World" Service Engine and pack it into an SU and SA, the project name is hello-world-SE-SU-SA and the single pieces are named analogous. For a custom project, the IDs and names shall be altered such that they describe the purpose or function of any piece of the SA.

Create a directory hello-world-SE-SU-SA and open a command line in this folder. Now execute the following command (it has to be one line but was split to be readable):

mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine
-DarchetypeVersion=3.0-incubating -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SE

The first three parameters identify the maven 2 archetype to use, while the last two parameters define the generated maven 2 project. The version information "3.0-incubating" may have to be changed; just look at any of ServiceMix' pom.xml for the version you are using. Maven uses the group ID (printed in pink) as default Java package (see in output below as well), thus invalid characters like minus, percent etc. must be avoided or a custom package name has to be given as parameter. The output looks like this (watch for the informations in bold letters):

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ----------------------------------------------------------------------------
...
[INFO] Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE
...
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] Archetype created in dir: C:\0hello-world-SE-SU-SA\hello-world-SE
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------

Maven creates a new folder having the same name as the artifact ID provided (printed in green in the command). Inside this folder, a file called pom.xml is created. This contains the Project Object Model providing Maven with all needed information for building, see Introduction to the POM at the Maven website. Moreover, Java source files and tests were created. The full structure of the things created by Maven for you looks like this (some directories are grouped together):

\hello-world-SE-SU-SA\hello-world-SE\
      pom.xml
      src\main\
            java\
                  org\apache\servicemix\
                        samples\helloWorldSE\
                              MyBootstrap.java
                              MyComponent.java
                              MyDeployer.java
                              MyEndpoint.java
                              MyLifeCycle.java
                              MySpringComponent.java
      test\
            java\
                  org\apache\servicemix\
                        samples\helloWorldSE\
                              MySpringComponentTest.java
            resources\
                  spring.xml

Now you might be wondering why all the classes have the word "My" prefixed to them. Don't worry these are just driven from the template, you just need to rename them to whatever you want to. Just make sure you change the corresponding resource files, change "My" to whatever prefix that you used for the classes.

3) Using an IDE to add meat to the component.

You can either use IDEA or Eclipse, I tried it with Eclipse so I guess I am going to stick it for now. <TODO>

Now you can build and test the code by executing

cd hello-world-SE

mvn test

This shall already include everything stated at http://www.servicemix.org/site/maven-jbi-plugin.html#MavenJBIplugin-GettingStarted
and http://www.servicemix.org/site/working-with-components.html
 

Be Careful

The body of the note here..

Packing into the SU

The archetypes for SUs and SAs do not contain much code, but rather help with tasks related to Maven. You will only need to adapt the generated POMs to your project - just little work, but requiring some guidiance. Here we go:

use the SU archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.html  

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units  

Packing into the SA 

As mentioned above\, the archetypes for SUs and SAs mainly help with tasks related to Maven.

use the SA archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.html
mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeVersion=3.0-incubating-SNAPSHOT -DgroupId=org.apache.servicemix.samples.helloWorldSE -DartifactId=hello-world-SA

manually editing http://www.servicemix.org/site/working-with-service-assemblies.html

  • No labels