ServiceMix can be used as a protocol bridge. The following tutorial will explain how to create a JBI Service Assembly (aka a JBI application) to bridge two different protocols. In this example, we will bridge the HTTP/SOAP with the JMS protocol. We will also put between the two protocols an XSLT transformation.
We will leverage ServiceMix archetypes and maven plugin (see Maven JBI plugin).
Identifying the service units
Our JBI SA (Service Assembly) will be composed of the following SUs (Service Units):
- an HTTP+SOAP consumer
- a pipeline to call the XSLT transformer and the JMS provider
- an XSLT transformer
- a JMS provider
Directory layout
We aim to have the following project structure:
Code Block |
---|
bridge\
pom.xml
bridge-http-su\
...
bridge-eip-su\
...
bridge-xslt-su\
...
bridge-jms-su\
...
bridge-sa\
...
|
Creating the archetypes
In the bridge directory, run the following commands:
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-http-consumer-service-unit \
-DarchetypeVersion=1.0-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.bridge \
-DartifactId=bridge-http-su
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-jms-provider-service-unit \
-DarchetypeVersion=1.0-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.bridge \
-DartifactId=bridge-jms-su
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-eip-service-unit \
-DarchetypeVersion=1.0-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.bridge \
-DartifactId=bridge-eip-su
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-lwcontainer-service-unit \
-DarchetypeVersion=1.0-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.bridge \
-DartifactId=bridge-xslt-su
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-service-assembly \
-DarchetypeVersion=1.0-incubating-SNAPSHOT \
-DgroupId=org.apache.servicemix.samples.bridge \
-DartifactId=bridge-sa
|
Main pom
Now that we have created the SUs and SA structure, let's write the main pom:
Code Block |
---|
|
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.servicemix.samples</groupId>
<artifactId>bridge</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>bridge-http-su</module>
<module>bridge-eip-su</module>
<module>bridge-xslt-su</module>
<module>bridge-jms-su</module>
<module>bridge-sa</module>
</modules>
</project>
|
We want the Service Assembly to include the 4 SUs that we just created.
So let's edit the pom and change the dependencies to:
Code Block |
---|
|
<dependencies>
<dependency>
<groupId>org.apache.servicemix.samples.bridge</groupId>
<artifactId>bridge-http-su</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.samples.bridge</groupId>
<artifactId>bridge-eip-su</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.samples.bridge</groupId>
<artifactId>bridge-xslt-su</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.servicemix.samples.bridge</groupId>
<artifactId>bridge-jms-su</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
|
Now, we should be able to launch maven and have a the SA generated in the bridge-sa/target/ directory. You can check that by running the following command from the bridge/ directory:
Of course, it won't work if you deploy it and we now need to fill the holes.
HTTP SU
We need to define a simple HTTP consumer endpoint in the http SU. As we do not use the request / response pattern, we will use an InOnly mep.
Code Block |
---|
|
<?xml version="1.0"?>
<beans xmlns:http="http://servicemix.apache.org/http/1.0"
xmlns:b="http://servicemix.apache.org/samples/bridge">
<http:endpoint service="b:http"
endpoint="endpoint"
targetService="b:pipeline"
role="consumer"
locationURI="http://localhost:8192/bridge/"
defaultMep="http://www.w3.org/2004/08/wsdl/in-only" />
</beans>
|
EIP SU
Code Block |
---|
|
<?xml version="1.0"?>
<beans xmlns:eip="http://servicemix.apache.org/eip/1.0"
xmlns:b="http://servicemix.apache.org/samples/bridge">
<eip:pipeline service="b:pipeline" endpoint="endpoint">
<eip:transformer>
<eip:exchange-target service="b:xslt" />
</eip:transformer>
<eip:target>
<eip:exchange-target service="b:jms" />
</eip:target>
</eip:pipeline>
</beans>
|
XSLT SU
Code Block |
---|
|
<?xml version="1.0"?>
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:b="http://servicemix.apache.org/samples/bridge">
<classpath>
<location>.</location>
<location>lib/servicemix-components-3.0-incubating-SNAPSHOT.jar</location>
</classpath>
<sm:serviceunit id="jbi">
<sm:activationSpecs>
<sm:activationSpec service="b:xslt" endpoint="endpoint">
<sm:component>
<bean class="org.apache.servicemix.components.xslt.XsltComponent">
<property name="xsltResource" value="classpath:bridge.xslt" />
</bean>
</sm:component>
</sm:activationSpec>
</sm:activationSpecs>
</sm:serviceunit>
</beans>
|
JMS SU
Code Block |
---|
|
<?xml version="1.0"?>
<beans xmlns:jms="http://servicemix.apache.org/jms/1.0"
xmlns:b="http://servicemix.apache.org/samples/bridge">
<jms:endpoint service="b:jms"
endpoint="endpoint"
role="provider"
destinationStyle="queue"
jmsProviderDestinationName="bridge.output"
connectionFactory="#connectionFactory" />
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost" />
</bean>
</beans>
|