Setup a Service unit and assembly to launch the Derby Network Server

Walkthrough

To create the Service unit and assembly and deploy it to Fuse ESB you need to do the following:

1. Set up the derby project

  • Prerequisites
  • Create a POM file for this project

2. Create a Servicemix bean Service unit

3. Create a Servicemix Service Assembly.

5. Deploy it to FUSE ESB 

1. Setting up the project 

Pre-requisites 

To create and run the use case you need to download and install the following:

  • FUSE ESB 3.3.0.6 or higher
  • JDK 1.5 or higher
  • Apache Maven 2.0.6 or higher
  • The Logisticx demo source code

After installing Maven, you need to change the following settings in your operating system environment:

  • Set the M2_HOME environment variable to point at the Maven root directory.
  • Add the Maven bin directory (%M2_HOME%\bin on Windows or $M2_HOME/bin on UNIX) to your PATH.

Creating a Maven Project

All our use cases are Maven based around the Logisticx demo. This use case is a sub-project of the Logisticx demo.

So the first thing to do is create a directory called "
LOGISTICX_DIR/derby" and place the following POM file within that directory.

Example 1.0: POM for Stock Processor

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.iona.fuse.demo.logisticx</groupId>
    <artifactId>logisticx-demo-parent</artifactId>
    <version>1.1-SNAPSHOT</version>
  </parent>

  <groupId>com.iona.fuse.demo.logisticx.derby</groupId>
  <artifactId>derby</artifactId>
  <version>${logisticx-version}</version>
  <name>Order Derby Parent Project</name>
  <packaging>pom</packaging>
</project>

We have given this project a groupId of com.iona.fuse.demo.logisticx.derby and an artifact of derby.

Run the following command to ensure everything builds ok.

=> mvn install

Also add the directory name as a module to the root Logisticx POM file. 

Example 1.1: Module definition
<modules>

<module>model</module>
    <module>derby</module>
   ....
  </modules>

We will now create our service unit and assembly from here.

3. Creating a Servicemix Bean Service unit

The Derby Service unit uses the ServiceMix Bean component which provides integration with beans (POJOs) with the JBI bus to make it easy to use POJOs to process JBI message exchanges.

This use case uses the Bean Name which will create a single instance per request (message exchange).

The pojo implements the following spring classes FactoryBean, InitializingBean, and DisposableBean. It launches the Derby Network Server Control on your localhost and on port 1527 by default. So it will be started and stopped correclty.

Run the following maven archetype command from the derby directory to create the skeleton project for the servicemix bean.

Example 1.5: Archetype command

mvn archetype:create \-DarchetypeGroupId=org.apache.servicemix.tooling
\-DarchetypeArtifactId=servicemix-bean-service-unit
\-DarchetypeVersion=3.3.1.5-fuse
\-DgroupId=com.iona.fuse.demo.logisticx.derby
\-DartifactId=derby-su
\-DremoteRepositories=[http://repo.open.iona.com/maven2/]

This creates a directory called derby-su.

Adding Configuration

Change the configuration for the derby bean in the generated xbean.xml file.

LOGISTICX_DIR/derby/derby-su/src/main/resources/xbean.xml

Example 1.3: Derby xbean file

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
       xmlns:test="urn:test">

       <classpath inverse="true" />

       <bean:endpoint id="derby-nsc"
                      beanName="derby"
                      service="test:dummy"
                      endpoint="dummy"/>

       <bean id="derby" class="com.iona.fuse.demo.logisticx.derby.NetworkServerBean" lazy-init="false"/>

</beans>

4. Creating the Derby Service Assembly


You will now create a Servicemix Service Assembly to wrap the service unit and deploy it to FUSE ESB. Use the archetype:create command again.

mvn archetype:create
\-DarchetypeGroupId=org.apache.servicemix.tooling
\-DarchetypeArtifactId=servicemix-service-assembly
\-DarchetypeVersion=3.3.1.5-fuse
\-DgroupId=com.iona.fuse.demo.logisticx.derby
\-DartifactId=derby-sa
\-DremoteRepositories=[http://repo.open.iona.com/maven2/]

This generates a project called derby-sa with a pom.xml file. Update the pom.xml file to add in the dependency on the service unit.

 Example 1.4: derby-sa POM

<?xml version="1.0" encoding="UTF-8"?><project>
  <modelVersion>4.0.0</modelVersion>

  <parent>
	  <groupId>com.iona.fuse.demo.logisticx</groupId>
	  <artifactId>logisticx-demo-parent</artifactId>
	  <version>1.1-SNAPSHOT</version>
  </parent>

  <groupId>com.iona.fuse.demo.logisticx.derby</groupId>
  <artifactId>derby-sa</artifactId>
  <packaging>jbi-service-assembly</packaging>
  <name>Derby SA</name>
  <version>${logisticx-version}</version>
  <url>http://www.myorganization.org</url>

  <dependencies>
    <dependency>
      <groupId>com.iona.fuse.demo.logisticx.derby</groupId>
      <artifactId>derby-su</artifactId>
      <version>${logisticx-version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>${servicemix-version}</version>
        <extensions>true</extensions>
        <configuration>
          <type>service-assembly</type>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

If you now run

=> mvn install

from the derby directory you should be ready to deploy your derby-sa to your installation of Servicemix.

5. Deploying to Fuse ESB

You are now ready to deploy your service assembly to FUSE ESB.

Deploying to Servicemix 3

Before you start, make sure that you have started ServiceMix.

You can navigate to your project's SA directory and use the JBI Maven plugin to deploy your project.

Run mvn jbi:projectDeploy

The command will not only deploy the service assembly, but also install any dependencies automatically. For this use case it will deploy the servicemix-bean component.

You may also copy the SA to the hotdeploy folder.

Deploying to Servicemix 4 

You are now ready to deploy your service assembly to FUSE ESB.

Copy the built artifact to the "deploy" directory of FUSE ESB 4.

Start Servicemix - you can check if the service has started by running the "jbi list" comand

Labels

 
(None)