Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Get on the Enterprise Service Bus with the Open Source Mule API : Page 2

Enterprise service bus is a generic name for any solution that provides communication and translation between applications or between different processes within an application. While Microsoft, IBM, and others have long offered commercial solutions for this integration problem, Mule is one of the first open source APIs. With Mule, data translation is not as hard as you once thought.




Application Security Testing: An Integral Part of DevOps

Getting Started with Mule
Mule is available at wiki.muleumo.org/display/MULEPROJ/Home. For this article I used version 0.9.3, which was the latest at time of writing. Download the ZIP file called mule-0.9.3-dist.zip (or whatever the equivalent version is), and unzip it to the C:\MULE directory on your hard drive. You should see a file and directory structure like that in Figure 1.

Figure 1. Mule Installation Directory: This is what you should see when you unpack the Zip file into a C:\MULE directory on your hard drive.
One thing you'll have to make sure of before running Mule is to have a valid J2SE SDK installed and that the JAVA_HOME environment variable is correctly set up. In addition, you should make sure that the CLASSPATH environment variable contains a reference to C:\Mule\lib and C:\Mule\dist (or whatever directory you installed to). Once all that is set up you are ready to start playing with your brand new enterprise bus.

The Hello World Example
Perhaps the most appropriate place to start is with a 'Hello World' application. This Hello World, though, is actually a lot more complicated than it appears: It demonstrates the input pipeline—which includes some nodes that process the document that is input to the pipeline—as well as an output pipeline that sends the new information back to the user. While this is very simplistic, it demonstrates some of the principles of the bus and provides a peek at some of the functionality and how it is handled by Mule, the messaging broker.

You can find this sample in the samples/hello directory of Mule. Start it by running START.BAT from the command line (see Figure 2). Entering your name will trigger the process to run (see Figure 3).

Figure 2. Hello MULE: This is what you should see when you run the 'Hello World' application from START.BAT.
Figure 3. Hello, You: Here is the Hello World application in action.

Figure 4 shows the flow of this application and how it works as an enterprise service bus using the Mule framework.
Figure 4. Mule Train: The document flow across the enterprise service bus in the 'Hello World' Application is shown.
The order in which the bus flows the message is determined by a combination of the configuration XML for the process and the internal logic within the individual nodes. However, to get the bus started, you have to specify the input to the process and this can be seen in the configuration XML file (conf/hello-mule-config.xml), some snippets of which are shown in Listing 1.

With that, you've just jumped into the deep end of configuration and flow, to show what should be a very simple process. So you might be a bit confused at this point, but that's perfectly acceptable. You have the basics now in order to see the big picture of everything going on in this application. Understanding will come shortly.

Referring to Listing 1 and Figure 4, you will see that the SystemStreamConnector is defined as the connector for this application and that GreeterUMO is the main 'object' that starts the processing for this application (in the mule-descriptor tag).

The SystemStreamConnector takes in a string but the application knows (via the receiveEndPoint attribute of the mule-descriptor) that it is to transform that string into an object that will move along the bus. The transformation is done by the StringToNameString application, which is implemented as a Java class in the snippet below. The full source code is available in the Mule download.

public class StringToNameString extends DefaultTransformer { public StringToNameString() { super(); this.registerSourceType(String.class); } public Object doTransform(Object src) throws TransformerException { String name = (String)src; int i = name.indexOf("\r"); if(i > -1) name = name.substring(0, i); return new NameString(name); } }

StringToNameString converts the incoming string containing your name (or whatever you typed in) into an object of NameString class (source also included) for use by the GreeterUMO. The GreeterUMO is implemented using the Greeter class (specified in the mule-descriptor using the 'implementation' attribute). This class then operates on the document and when finished the framework sends it onto the next node, specified by the sendEndPoint attribute. In this case the next node is the chitchatter.

The chitchatter node is described using the <mule-descriptor> for ChitChatUMO (Listing 1). In a similar vein as the greeter, chitchatter uses a transform to convert the incoming document from a NameString to a Chatstring. This is achieved using the NameStringToChatString class (also in the download). The output of this class (again specified in the <mule-descriptor>) is the ChatStringToString transformer, which takes the Document (now a ChatString object) and converts it into a string. This string is eventually passed to the StreamConnector, which writes it back out to the console, providing a 'hello world' implementation.

By starting the Mule server application and specifying this configuration, you have implemented this service bus to handle the following process:

  • taking the input from the SystemStreamConnector (which handles the keyboard)
  • converting the input document to the document formats that the various nodes in the process understand
  • acting on these documents as specified
  • and converting the documents back to the format that the Stream Connector understands for output.
The final effect of this process is very simple: Input 'Bill Gates' to get an output of 'Hello, Bill Gates, How are you'.

To start up the server with this configuration issue the following command:

java -classpath "%MULE_PATH%" org.mule.MuleServer <config path>

Where %MULE_PATH% is the path to the mule JARS, and <config path> is the location of your configuration file specifying how the ESB is set up (as seen in Listing 1).

Next Steps
This example was very simple in functionality but it demonstrated many of the principles of how an enterprise service bus works. And it should help you get started in configuring and extending the Mule enterprise service bus.

Mule is an enormous and very flexible framework that allows you to build such applications. If you are looking to build an agile business, and don't want to spend the heavy dollars that something like BizTalk would cost, it is well worth a look.

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date