Filed under: J2EE, Java, Maven, — Tags: ESB, JBoss, xml — Thomas Sundberg — 2010-07-09
I want to build a Hello World example for JBoss ESB using Maven instead of Ant. The original example bundled with JBoss ESB is using Ant. I have created a pom.xml that will do all the magic and re-located the example files to fit into a Maven structure.
Let's start with the file layout:
src --- main ---+-- java -------+------ se.sigma.maven.esb.helloworld.JMSListenerAction | | +-- resources --+-- jbm-queue-service.xml | | +-- META-INF --+-- deployment.xml | | +-- jboss-esb.xml pom.xml
We will be using five files. The magic is done in the Maven file pom.xml and the service is defined by the four remaining files.
The Maven pom.xml looks like this:
<project> <modelVersion>4.0.0</modelVersion> <groupId>se.sigma.maven</groupId> <artifactId>esb-hello-world</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>ESB Hello World</name> <repositories> <repository> <id>jboss</id> <name>JBoss</name> <url>https://repository.jboss.org/nexus/content/groups/public-jboss</url> <layout>default</layout> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jboss-packaging-maven-plugin</artifactId> <version>2.1.1</version> <extensions>true</extensions> <configuration> <archiveName>Quickstart_helloworld</archiveName> </configuration> <executions> <execution> <id>build-esb</id> <goals> <goal>esb</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.jboss.soa.bpel.dependencies.esb</groupId> <artifactId>jbossesb-rosetta</artifactId> <version>4.8</version> <type>jar</type> <scope>provided</scope> </dependency> <dependency> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> <version>1.1</version> <type>jar</type> <scope>provided</scope> </dependency> </dependencies> </project>
The parts to notice here are the JBoss repository and the plugin jboss-packaging-maven-plugin.
The dependencies we need aren't available at Maven central so we want to define a JBoss repository for getting hold of the jbossesb-rosetta dependency. Normally you should use a dependency manager such as Nexus to cache remote repositories, but this wouldn't give me a chance to build a standalone pom that will work out of the box.
Building an ESB archive isn't a native part of Maven. We will therefore use the jboss-packaging-maven-plugin to assemble the files needed and create the ESB archive. I don't want to name the artifact 'esb-hello-world-1.0.esb'. The solution is to define an archiveName in the configuration part of the plugin.
I want to build the ESB archive every time the Maven life cycle phase 'package' is executed. The jboss-packaging-maven-plugin is bound to the package life cycle, but we need to define which goal to execute. This is done in the execution section.
The rest of the files used are copied from the JBoss example. I have reformatted them using IntelliJ IDEA.
The actual action class is defined as:
package se.sigma.maven.esb.helloworld; import org.jboss.soa.esb.actions.AbstractActionLifecycle; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.message.Message; public class JMSListenerAction extends AbstractActionLifecycle { protected ConfigTree config; public JMSListenerAction(ConfigTree config) { this.config = config; } public Message displayMessage(Message message) throws Exception { System.out.println("================================================"); System.out.println("Body: " + message.getBody().get()); System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); return message; } }
A deployment descriptor, deployment.xml, is defined as:
<jbossesb-deployment> <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb</depends> <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw</depends> </jbossesb-deployment>
An esb descriptor, jboss-esb.xml, is defined as:
<?xml version = "1.0" encoding = "UTF-8"?> <jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5"> <providers> <jms-provider name="JBossMQ" connection-factory="ConnectionFactory"> <jms-bus busid="quickstartGwChannel"> <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_helloworld_Request_gw"/> </jms-bus> <jms-bus busid="quickstartEsbChannel"> <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_helloworld_Request_esb"/> </jms-bus> </jms-provider> </providers> <services> <service category="FirstServiceESB" name="SimpleListener" description="Hello World"> <listeners> <jms-listener name="JMS-Gateway" busidref="quickstartGwChannel" is-gateway="true"/> <jms-listener name="helloWorld" busidref="quickstartEsbChannel"/> </listeners> <actions mep="OneWay"> <action name="action1" class="se.sigma.maven.esb.helloworld.JMSListenerAction" process="displayMessage"/> <action name="action2" class="org.jboss.soa.esb.actions.SystemPrintln"> <property name="printfull" value="false"/> </action> <!-- The next action is for Continuous Integration testing --> <action name="testStore" class="org.jboss.soa.esb.actions.TestMessageStore"/> </actions> </service> </services> </jbossesb>
The queue service, jbm-queue-service.xml, is defined as:
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.jms.server.destination.QueueService" name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb" xmbean-dd="xmdesc/Queue-xmbean.xml"> <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends> <depends>jboss.messaging:service=PostOffice</depends> </mbean> <mbean code="org.jboss.jms.server.destination.QueueService" name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw" xmbean-dd="xmdesc/Queue-xmbean.xml"> <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends> <depends>jboss.messaging:service=PostOffice</depends> </mbean> </server>