Maven Archetype for Mule Projects
When MuleForge first opened a couple of years ago I submitted a Maven Archetype for simple Mule applications. After the recent upgrade of MuleForge the project was suddenly not available anymore, still I regularly meet developers who show a keen interest in my archetype. So, I decided to upgrade it to Mule 2.0.* and post it here instead.
Basically, the Maven Mule Archetype creates a skeleton Mule Project with a runnable demo application inside. The idea is that by providing a simple Mule Project that demonstrates different aspects of Mule, new users will be able to do their own modifications and get up and running in no-time. The demo application is composed as described in the following figure:
The Project asks for input from System.in. The input is split into multiple messages where each word is sent as a separate message. This is handled by the Splitter attached to output of the ‘Gate.In' component. Each word is then capitalized by the CapitalizedUMO and then reversed by the ReverseUMO. The separate word messages are then aggregated into a single message by the Aggregator attached to the input of the ‘Gate.Out' component, and sent to System.out.
The CapitalizeUMO only accept messages containing lower-case a-z characters, which is enforced by the filter attached to the input of the UMO. Rejected messages are sent to System.err. The ReverseUMO will throw an exception if a received messages is a palindrome. The exception is intercepted and sent to System.err.
So, how to you use the Archetype? Well, first you need Maven 2 installed. If that is the case, the archetype itself has to be made available to Maven 2. First you download the archetype plugin JAR file to a directory of choice and then you enter the following commands:
cd <directory-of-choice-where-the-file-was-downloaded-to> mvn install:install-file \ -DgroupId=no.jforce.mule \ -DartifactId=maven-mule-archetype \ -Dversion=0.3 \ -Dfile=maven-mule-archetype-0.3.jar \ -Dpackaging=maven-plugin
Having installed the archetype, the following command will generate a project for you inside the directory from where you’re running the command:
mvn archetype:create \ -DarchetypeGroupId=no.jforce.mule \ -DarchetypeArtifactId=maven-mule-archetype \ -DarchetypeVersion=0.3 \ -DgroupId=<your-groupId> \ -DartifactId=<your-artifactId> \ -Dversion=<your-version>
You should now have a project folder called <artifactId> with a generated Maven 2 project inside. Congratulations, you’re halfway there
The following step is now to create a project that is importable into Eclipse, IDEA, NetBeans etc. For this example I’ll stick with Eclipse. Enter the following commands to generate an Eclipse project:
cd <artifactId>
mvn eclipse:eclipse
This command will generate the Eclipse .project and .classpath files that now makes the project a valid Eclipse project. Startup eclipse and import this project into your Eclipse workspace using the File > Import > Existing Project action.
You will now have your brand new Mule-project listed inside Eclipse.
If this is the first time you generate Eclipse projects using Maven 2, you’ll get a lot of red flags (errors). This is because you need to tell Eclipse where your local Maven repository is. The project classpath refers to artifacts that lie inside this repository. Just setup an Eclipse Variable called M2_REPO and you’re good to go. The following reference will tell you how.
Now, open your project’s StartServer class and run it. This (hopefully) will start the Mule, inside Eclipse, and run your application. When started the application will prompt you for your name in the console window:
That’s it. Now you are running Mule inside Eclipse, like a normal Java-project. Enjoy.
March 28th, 2008 at 8:19
Several errors: the link for the jar points to a zip file; maven complained so I renamed it to …0.3.jar; looks like it installs, but I get OldArchetype does not exist http://repo1.maven.org/maven2/no/jforce/mule/maven-mule-archetype/0.3/maven-mule-archetype-0.3.jar; I am new to maven and am sure this is something simple. any help appreciated. thanks. -Norm
April 1st, 2008 at 6:55
Aargh.. that bites. Can you try prividing the mvn -U option when creating your project. Does that help in any way?
May 20th, 2008 at 7:42
Really appreciate the attempt here as I’m a MUle newbie struggling to understand Mule config components (poor naming IMHO).
Anyway I can’t get the StringTokenAggregatorRouter to aggregate.
Lots of
StringTokenAggregatorRouter - Attempting to route event: ..
StringTokenAggregatorRouter - Correlation Group Size not set, but CorrelationAggregator is being used. Message is being forwarded
StringTokenAggregatorRouter - Starting aggregationEventGroup {id=no-id, expected size=-1, current events=1 ..
And the Aggregator gets called once for each word.
Its strange because I definitely see
StringSplitterOutboundRouter - java.util.List payload detected, setting correlation group size to 4
at the start
May 20th, 2008 at 8:44
Are you some of your entered words aren’t rejected by the filter?
May 26th, 2008 at 4:51
I explicitly replaced the filter with something a little more benign as I didn’t have much luck with the regex filter. My filter just rejects any word that matches ‘dog’
OK, now I’m confused about whether they have been aggregated or not. The StringTokenAggregatorRouter is called once for each message (ie once for each word), not once to aggregate the elements of the initial message.
But this does result in a String being written to System.out that contains all the words supplied in the initial message uppercased and reversed, but the words are not in any particular order and in fact change from time to time.
Eg starting with ‘one two three four five’ returns a String of ‘OWTENOEVIFRUOFEERHT’
1) Are multiple calls to the Aggregator to be expected?
2) Should order not be preserved?
May 26th, 2008 at 6:56
And in fact if I replace
with
then I get loggingUMO called once for each word of the original message. Ie the split message aren’t being aggregated. Is there something extra that I need to do to aggregate the messages?
May 26th, 2008 at 6:58
I’ll try again, escaping the special chars:
If I replace
<!–bridge-component/ –>
with
<component>
<spring-object bean=”loggingUmo”/>
</component>
then I get loggingUMO called once for each word of the original message. Ie the split message aren’t being aggregated. Is there something extra that I need to do to aggregate the messages?
July 29th, 2008 at 1:22
Hi,
I found your plugin very useful. thanks for the work.
one quick question, in my present project, we are asked to use spring on top of mule, so ur templates is just sufficient for that right?
Thanks
Harinath
August 17th, 2008 at 6:53
Hi Harinath,
Yes, my template introduces a separation between the Mule-specific configuration and Spring-stuff.