Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Creating a Hello World

...

JBI

...

Note

The content of this document overlaps a bit with Creating a Standard JBI Component and Notes on Creating JBI Component using maven2. Any changes you might want to make to this document may be relevant for these documents as well. In addition, questions not answered by this document may be answered by the one of those documents.

Note

The Roadmap for a perspective Servicemix developer can be very useful, especially for new users as it focuses on using the samples and components shipped with ServiceMix.

This tutorial describes how to create a very simple Hello World style of JBI service engine (SE) component. It demonstrates some best practices for creating JBI components. The example in this tutorial is as minimalistic as possible so as to focus on key concepts and not drown in details. The example component will respond to all requests with the message:

Panel

Hello, I received <xyz> bytes!

Note
titleTODO

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

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).
http://www.servicemix.org/site/notes-on-creating-jbi-component-using-maven2.html version14
http://www.servicemix.org/site/creating-a-standard-jbi-component.html version26
are already fully incorporated in the mentioned versions, so delete content and point from there to here (and delete note at the very top)

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

provide additional reading
Creating a protocol bridge.for a "bigger" example
The examples page lists examples providing more information, showing further possibilities and components.

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 or higher
  • 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.

JBI components are can be thought of as the smallest applications or services accessible in a service-oriented architecture. Each service has a very specific purpose and therefore a narrow scope and set of functionality. Components come in two flavours: Service Engine (SE) and Binding Components (BC). Several SUs are packed into a SA. An SA is a complete application consisting of one or more services interacting with one another.

See also the page providing information on working with service units

Below are some quick definitions:

  • Component Architecture
    • Binding Components - Components that provide or consume services via some sort of communications protocol or other remoting technology
    • Service Engines - Components that supply or consume services locally (within the JBI container)
  • Component Packaging
    • Service Units - Packaging for an individual service that allows deployment to the JBI container; similar to a WAR file from J2EE
    • Service Assemblies - Packaging for groups of SUs for deployment to the JBI container; similar to an EAR file from J2EE

For further reading, see the JBIforSOI document for a good introduction to JBI.

Note
titleTODO

Further reading: JSR 208. Include references from here to sections/pages in the spec. Maybe add an attachment to this wiki page containing a FDF (annotations for the PDF) so skimming the sepc quickly without missing important information is possible.

Creating the Maven Projects for Each Component

Service Engine

This tutorial describes how to create a very simple Hello World style of JBI service engine (SE) component. It demonstrates some best practices for creating JBI components. The example in this tutorial is as minimalistic as possible so as to focus on key concepts and not drown in details. The example component will respond to all requests with the message:

Panel

Hello, I received <xyz> bytes!

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 or higher
  • 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.

JBI components are can be thought of as the smallest applications or services accessible in a service-oriented architecture. Each service has a very specific purpose and therefore a narrow scope and set of functionality. Components come in two flavours: Service Engine (SE) and Binding Components (BC). Several SUs are packed into a SA. An SA is a complete application consisting of one or more services interacting with one another.

See also the page providing information on working with service units

Below are some quick definitions:

  • Component Architecture
    • Binding Components - Components that provide or consume services via some sort of communications protocol or other remoting technology
    • Service Engines - Components that supply or consume services locally (within the JBI container)
  • Component Packaging
    • Service Units - Packaging for an individual service that allows deployment to the JBI container; similar to a WAR file from J2EE
    • Service Assemblies - Packaging for groups of SUs for deployment to the JBI container; similar to an EAR file from J2EE

For further information on JBI, see the JBI section of the User's Guide. See also the JBIforSOI document for a decent introduction to JBI.

Creating the Maven Projects for Each Component

Creating a Maven Subproject For the JBI Service Engine

The focus of this section is on the creation of a JBI 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

As this text describes how to create a Hello World service engine and pack it into a SU and SA, the project name is hello-world-se and each piece of the SA puzzle are named using a similar pattern. For a given project, the IDs and names shall be altered such that they describe the purpose or function of the given piece of the SA.

1) Create a directory named hello-world-smx and switch to that directory:

Code Block

$ mkdir hello-world-smx
$ cd hello-world-smx

2) Use the servicemix-service-engine Maven archetype to generate a Maven project for the SE:

Panel

$ mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-service-engine \
-DarchetypeVersion=3.1-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.helloworld.se \
-DartifactId=hello-world-se

The command above will create a directory named hello-world-se that houses a Maven project for the JBI service engine being created here. The name of the directory is taken from the artifactId parameter.

The first three parameters to the mvn command (-DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine -DarchetypeVersion=3.1-incubating-SNAPSHOT) identify which Maven archetype to use for the archetype:create goal, while the last two parameters (-DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-se) uniquely identify the Maven project that is being generated. The groupId (printed in pink) is used as the Java package and the artifactId is used as the project name. Therefore, only alphanumeric characters are valid values for the groupId and artifactId parameters.

Tip

The value of the archetypeVersion parameter in the command above (3.1-incubating-SNAPSHOT) may need to be updated to the current ServiceMix version in order for the command to work correctly. The latest version can always be found in the top level ServiceMix POM in the <version> element.

The output from executing the archetype:create goal is shown below (only relevant information has been preserved):

Panel

Wiki Markup
\[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

Creating a Maven Subproject For the JBI Service Engine

The focus of this section is on the creation of a JBI 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

As this text describes how to create a Hello World service engine and pack it into a SU and SA, the project name is hello-world-se and each piece of the SA puzzle are named using a similar pattern. For a given project, the IDs and names shall be altered such that they describe the purpose or function of the given piece of the SA.

1) Create a directory named hello-world-smx and switch to that directory:

Code Block

$ mkdir hello-world-smx
$ cd hello-world-smx

2) Use the servicemix-service-engine Maven archetype to generate a Maven project for the SE:

Panel

$ mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-service-engine \
-DarchetypeVersion=3.1-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.helloworld.se \
-DartifactId=hello-world-se

The command above will create a directory named hello-world-se that houses a Maven project for the JBI service engine being created here. The name of the directory is taken from the artifactId parameter.

The first three parameters to the mvn command (-DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine -DarchetypeVersion=3.1-incubating-SNAPSHOT) identify which Maven archetype to use for the archetype:create goal, while the last two parameters (-DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-se) uniquely identify the Maven project that is being generated. The groupId (printed in pink) is used as the Java package and the artifactId is used as the project name. Therefore, only alphanumeric characters are valid values for the groupId and artifactId parameters.

Tip

The value of the archetypeVersion parameter in the command above (3.1-incubating-SNAPSHOT) may need to be updated to the current ServiceMix version in order for the command to work correctly. The latest version can always be found in the top level ServiceMix POM in the <version> element.

The output from executing the archetype:create goal is shown below (only relevant information has been preserved):

Panel

Wiki Markup
\[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\] <span style="color: #ff00ff">Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE</span>
...
\[INFO\] **\**\**\**\**\**\**\**\**\**\* End of debug <span style="color: #ff00ff">Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE</span>
...
\[INFO\] **\**\**\**\**\**\**\**\**\**\* End of debug info from resources from generated POM **\**\******************\*
\[INFO\] <span style="color: #009900">Archetype created in dir: /Users/bsnyder/src/hello-world-se/hello-world-se</span>
\[INFO\] \-----------------------------------------------------------------------\-
\[INFO\] BUILD SUCCESSFUL
\[INFO\] \-----------------------------------------------------------------------\-

...

No Format
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building A custom project
[INFO]    task-segment: [test]
[INFO] ----------------------------------------------------------------------------
...
[INFO] [compiler:compile]
...
[INFO] [surefire:test]
[INFO] Setting reports dir: c:\java\tmp\servicemix-helloWorldSE\target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
[surefire] Running org.apache.servicemix.samples.helloWorldSE.MySpringComponentTest
...
[surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1,422 sec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ---------------------------------------------------------------------------
...
Note
titleTODO

Maybe add further testing at the end of the tutarial ("how to continue when having the working example")

Generation and Deployment of the SA

...

-
...
Note
titleTODO

Maybe add further testing at the end of the tutarial ("how to continue when having the working example")

Generation and Deployment of the SA

The execution of the install goal above packages not only each component individually, it also packages the components together into a single SA. Of course, the code does not yet do anything, but we can already deploy the SA ServiceMix by switching to the hello-world-se/hello-world-sa directory and executing the jbi:projectDeploy goal like so:

Code Block

$ mvn jbi:projectDeploy

This tells the Maven JBI plugin to deploy the components to ServiceMix. When the deployment is complete, ServiceMix will output the following:

No Format

INFO  - ServiceAssemblyLifeCycle       - Starting service assembly: hello-world-sa

This output tells us that the SA was successfully deployed to ServiceMix.

Note
titleDeploying Component Dependencies

When working with the jbi:projectDeploy you may want to disable dependency deployment. When deploying to a server which has other components sharing these dependencies, they can cause problems during deployment. To stop the Maven JBI plugin from undeploying and redeploying dependencies each time, alter its configuration by disabling the deployment of dependencies using the following:

Code Block

<build>
<plugins>
  <plugin>
    <artifactId>jbi-maven-plugin</artifactId>
    <configuration>
      <deployDependencies>false</deployDependencies>
    </configuration>
  </plugin>
</plugins>
</build>

The configuration above introduces the deployDependencies element to the Maven JBI plugin and sets it to false.

For a few more configurable options on the Maven JBI plugin, see also Ability to configure jbi:projectDeploy goal to exclude updating dependencies.

Adding Functionality to the Component

We're now ready to add a bit of functionality to the component. Using an IDE like IntelliJ IDEA or Eclipse make this task much easier. The steps described here apply to Eclipse.

Tip
titleGenerate Eclipse Project Files

In order to import the SE into Eclipse, tell Maven to generate the necessary project and classpath files, switch to the hello-world-se

...

directory and

...

execute the following Maven goal:

Code Block

$ mvn 
jbi
eclipse:
projectDeploy
eclipse

This

...

No Format

INFO  - ServiceAssemblyLifeCycle       - Starting service assembly: hello-world-sa

...

will allow the SE to be imported into Eclipse for adding functionality.

Note
titleDeploying Component Dependencies

When working with the jbi:projectDeploy you may want to disable dependency deployment. When deploying to a server which has other components sharing these dependencies, they can cause problems during deployment. To stop the Maven JBI plugin from undeploying and redeploying dependencies each time, alter its configuration by disabling the deployment of dependencies using the following:

Code Block

<build>
<plugins>
  <plugin>
    <artifactId>jbi-maven-plugin</artifactId>
    <configuration>
      <deployDependencies>false</deployDependencies>
    </configuration>
  </plugin>
</plugins>
</build>

The configuration above introduces the deployDependencies element to the Maven JBI plugin and sets it to false.

For a few more configurable options on the Maven JBI plugin, see also Ability to configure jbi:projectDeploy goal to exclude updating dependencies.

Adding Functionality to the Component

We're now ready to add a bit of functionality to the component. Using an IDE like IntelliJ IDEA or Eclipse make this task much easier. The steps described here apply to Eclipse.

Tip
titleGenerate Eclipse Project Files

In order to import the SE into Eclipse, tell Maven to generate the necessary project and classpath files, switch to the hello-world-se directory and execute the following Maven goal:

Code Block

$ mvn eclipse:eclipse

This will allow the SE to be imported into Eclipse for adding functionality.

TODO

The default implementation of the component accepts InOut MEPs (ADD
LINK TO FURTHER READING CONCERNING MEPs) and return the input content
as the out message. This is already nearly what we want.

OUTLINE for further work:

  • Get Messages
  • read Messages
  • Wiki Markup
    count the bytes
    Maybe easiest by XSLT endpoint (can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.) see \[ servicemix-saxon\|servicemix-saxon\]
  • send a message back
  • Configure SA so that the example receives messages
    create & populate
    C:\hello-world-SE-SU-SA\hello-world-SU\src\main\resources\servicemix.xml
  • as MyDeployer extends AbstractXBeanDeployer create xbean.xml for SU
  • make something send messages (eg quartz timer, HTTP POST,...) and dump the answer (eg TraceComponent, FireWriter, EIP,...)
  • add a chapter what user may do now / "how to continue when having the working example"

Classpath for SU to include manually till v3.1, see mail

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units
manually editing http://www.servicemix.org/site/working-with-service-assemblies.html
use the SU archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.html
use the SA archetype like in http://www.servicemix.org/site/creating-a-protocol-bridge.html

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

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).
http://www.servicemix.org/site/notes-on-creating-jbi-component-using-maven2.html version14

Note
titleTODO

The default implementation of the component accepts InOut MEPs (ADD
LINK TO FURTHER READING CONCERNING MEPs) and return the input content
as the out message. This is already nearly what we want.

OUTLINE for further work:

  • Get Messages
  • read Messages
  • Wiki Markup
    count the bytes
    Maybe easiest by XSLT endpoint (can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.) see \[ servicemix-saxon\|servicemix-saxon\]
  • send a message back
  • Configure SA so that the example receives messages
    create & populate
    C:\hello-world-SE-SU-SA\hello-world-SU\src\main\resources\servicemix.xml
  • as MyDeployer extends AbstractXBeanDeployer create xbean.xml for SU
  • make something send messages (eg quartz timer, HTTP POST,...) and dump the answer (eg TraceComponent, FireWriter, EIP,...)
  • add a chapter what user may do now / "how to continue when having the working example"

Classpath for SU to include manually till v3.1, see mail

manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units
manually editing http://www.servicemix.org/site/working-with-service-assemblies.html
use the SU archetype like in creating-a-standard-jbi-component.html version26
are already fully incorporated in the mentioned versions, so delete content and point from there to here (and delete note at the very top)

This shall already include everything stated at
http://www.servicemix.org/site/creatingmaven-ajbi-protocol-bridge.html
use the SA archetype like in plugin.html#MavenJBIplugin-GettingStarted
and
http://www.servicemix.org/site/creating-a-protocol-bridge.htmlworking-with-components.html

provide additional reading
Creating a protocol bridge.for a "bigger" example
The examples page lists examples providing more information, showing further possibilities and components.

Additional Resources