Posts Tagged ‘ServiceMix ESB deploy sample’

Writing sample configurations for Apache ServiceMix

ServiceMix is an open source ESB by Apache Software Foundtion. This post will provide a brief description on creating new sample configurations and running them with ServiceMix

I have created sample configurations for five different scenarios.

The Direct Proxy

This is a basic scenario where a client issues a POST request and the ESB sends request to a specified service without any changes to the original message.
This cofiguration needs a http-consumer and a http-provider.

Steps to create the project

  • Create a folder and name it “direct-proxy”
  • Add a pom.xml file to the folder with following configuration
<?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>
        <groupId>org.apache.servicemix.http.proxy</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <name>SMX-HTTP :: DirectProxy</name>
        <url>http://servicemix.apache.org</url>
     </project>
  • cd direct-proxy
  • Create a comsumer service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-http-consumer-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=proxy-consumer-su
  • Create a provider service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-http-provider-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=proxy-provider-su
  • Create the Service Assembly
mvn archetype:create -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=proxy-sa

After executing the above commands you will find three folders created in the ‘direct-proxy’ folder.

  • Navigate to the ‘proxy-sa’ folder and add the created service units as dependencies to the pom.xml file.

e.g ;

<dependencies>
    <dependency>
         <groupId>org.apache.servicemix.http.proxy</groupId>
         <artifactId>proxy-provider-su</artifactId>
         <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.servicemix.http.proxy</groupId>
        <artifactId>proxy-consumer-su</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>
  • Then navigate to ‘proxy-consumer-su’ and ‘proxy-provider-su’ and check if the generated pom.xml files have specified the componentName. If not specify the component name as follows.
<properties>
    <componentName>servicemix-http</componentName>
</properties>

Now you are ready to deploy the configuration.

  • Do the necessary changes to the xbean files in ‘proxy-consumer-su’ and ‘proxy-provider-su’.

{source}

  • Start servicemix –
    1. cd <servicemix-home>/bin
    2. ./servicemix
  • Build the project
    1. cd direct-proxy
    2. mvn clean install

The project should build without any errors

  • Navigate to direct-proxy/proxy-sa/target. Copy the zip file and paste it to <servicemix-home>/deploy folder.

The Content Based Router

The content based router will evaluate the POST request issued by the client. If the evaluation passes the request is sent to a specified service.
This configuration evaluates the request using xpath. Apache Camel is used to define routes and to perform the xpath evaluation.

Steps to create the project

  •  Create a folder and name it as “router”
  • Add a pom.xml file to the folder with following configuration
<?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>
    <groupId>org.apache.servicemix.cbr.camel</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>SMX-CAMEL :: CBRProxy</name>
    <url>http://servicemix.apache.org</url>
</project>
  •  cd router
  • create the ServiceMix Camel service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-camel-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=cbr-camel-su
  • Create a comsumer service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-http-consumer-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=cbr-consumer-su
  • Create a provider service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-http-provider-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=cbr-provider-su
  • Create the Service assembly
mvn archetype:create -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=cbr-sa

There will be four folders created inside the ‘router’ folder

  •  Navigate to the ‘cbr-sa’ folder and add the created service units as dependencies to the pom.xml file.(refer the direct proxy)
  • Then navigate to ‘cbr-consumer-su’ and ‘cbr-provider-su’ and check if the generated pom.xml files have specified the componentName. If not, specify the  component name as follows.
<properties>
    <componentName>servicemix-http</componentName>
</properties>

Also check the pom generated in ‘cbr-camel-su’. If the componenName is not specified, if not specify it as follows

<properties>
    <componentName>servicemix-camel</componentName>
</properties>

To get this configuration working I had to replace the following of the pom.xml in cbr-camel-su

<dependency>
    <groupId>org.apache.servicemix</groupId>
    <artifactId>servicemix-camel</artifactId>
    <scope>provided</scope>
</dependency>

with

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>2.8.0</version>
</dependency>

Before this replacement I could not deploy the project due to “Error creating bean with name ‘camel’: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.servicemix.cbr.camel.MyRouteBuilder.from”

Now you are ready to deploy the configuration.

  • Do the necessary changes to the xbean files, camel contex and MyRouteBuilder.

{source}

  • Start servicemix – cd <servicemix-home>/bin

./servicemix

  • Build the project

cd router
mvn clean install
The project should build without any errors

  • Navigate to direct-proxy/proxy-sa/target. Copy the zip file and paste it to <servicemix-home>/deploy folder.

XSLT Transformation

This configuration transforms POST request using a XSLT stylesheet in the ESB, then sends the transformed request to an echo service. The echo service echo backs the received request. The echoed back transformed request is again transformed back to the original state, using another XSLT style sheet and sent back to the client. The Camel pipeline pattern is used for this.

  • Create a folder and name it as “xslt”
  •  add a pom.xml file to the folder with following configuration
 <?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>
<groupId>org.adroitlogic.com</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SMX-CAMEL :: XSLT</name>
<url>http://servicemix.apache.org</url>
</project>

  • cd xslt
  • create the camel service unit
mvn archetype:create -DarchetypeArtifactId=servicemix-camel-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-camel-su
  • create transform-back-xslt-su
mvn archetype:create -DarchetypeArtifactId=servicemix-saxon-xslt-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-back-xslt-su
  • creat transform-xslt-su
mvn archetype:create -DarchetypeArtifactId=servicemix-saxon-xslt-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-xslt-su
  • create transform-xslt-comsumer-su
mvn archetype:create -DarchetypeArtifactId=servicemix-http-consumer-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-xslt-consumer-su
  • create transform-xslt-provider-su
mvn archetype:create -DarchetypeArtifactId=servicemix-http-provider-service-unit -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-xslt-provider-su
  • create the SA
mvn archetype:create -DarchetypeArtifactId=servicemix-service-assembly -DarchetypeGroupId=org.apache.servicemix.tooling -DartifactId=transform-sa

There will be four folders vreated inside the ‘router’ folder

  • Navigate to the ‘cbr-sa’ folder and add the created service units as dependencies to the pom.xml file.

        org.apache.servicemix.xslt.transform
        transform-back-xslt-su
        1.0-SNAPSHOT

        org.apache.servicemix.xslt.transform
        transform-camel-su
        1.0-SNAPSHOT

        org.apache.servicemix.xslt.transform
        transform-xslt-consumer-su
        1.0-SNAPSHOT

        org.apache.servicemix.xslt.transform
        transform-xslt-provider-su
        1.0-SNAPSHOT

        org.apache.servicemix.xslt.transform
        transform-xslt-su
        1.0-SNAPSHOT

  •  Then navigate to ‘transform-xslt-consumer-su’ and ‘transform-xslt-provider-su’ and check if the generated pom.xml files have specified the componentName. If not, specify the component name as follows.
servicemix-http

Check the pom generated in ‘transform-camel-su’. If the componenName is not specified, if not specify it as follows


     servicemix-camel

Check the pom generated in ‘transform-back-xslt-su’ and ‘transform-xslt-su’. If the componenName is not specified, if not specify it as follows


     servicemix-saxon

  • Do the necessary changes to the xbean files, camel contex and MyRouteBuilder.
  • Start servicemix – cd <servicemix-home>/bin

./servicemix

  • Build the project

cd router
mvn clean install
The project should build without any errors

  •  Navigate to direct-proxy/proxy-sa/target. Copy the zip file and paste it to <servicemix-home>/deploy folder.

So this is how you create, build and deploy samples in ServiceMix. However I think the overhead is too much. It is needed to build a project each time a new sample is deployed, unlike in most other ESBs where deployin a new sample is just a matter of creating a sample configuration file and you are up and running 🙂

Advertisements