This page last changed on Oct 02, 2006 by lajos@mulesource.com.

The following section describes the configuration and behavior of the Hello world sample provided with the Mule distribution.

This sample uses two components to create a hello world message. When the sample starts it prompts the user at the console to type in their name, the user's name is then passed to the first component which adds something to the string before passes on to the second component that also adds some text before outputting the results back to the console.

Obviously there are much easier ways to achieve this same result, but the sample is used to demonstrate event flows in a Mule application. The aim of Mule is to simplify the development of distributed applications, but as a result there is a little more work to set up a simple console application . Cannot resolve external resource into attachment.

Running the Application

Prerequisites

To run you will need the following -

Optional

  • If you are asked to execute any Maven commands you'll need the Maven build tool from Apache. Mule has been tested with Maven 1.0.2. (Download Maven 1.0.2)

Running

  1. Open a shell*.
  2. From the root of the Mule distribution go to examples/ant/hello or examples/maven/hello
  3. Run the hello script* - you will be prompted to choose a configuration:
    1. Simple Configuration - example using Mule Xml configuration
    2. Spring-based Configuration - example using Spring beans configuration
    3. Receive events via HTTP - examples that accepts requests over http.
  4. Choose either the "Simple Configuration" or "Spring-based Configuration" and you will be prompted to enter your name.
  5. Choose the "Receive events via HTTP" option and you can invoke the hello service by going to your browser and going to: http://localhost:8888?name=Ross
  6. Shutdown Mule by typing 'CTRL-C'

-
*Shell refers to a command shell in unix or linux and command prompt in windows.

Walk through

The Hello World example prompts the user at the console to enter their name, which triggers an inbound event to the first component containing the users name. There are two components configured in the Hello world example -

  1. The GreeterUMO - Receives a name, say Ross, and prepends 'Hello'.
  2. The ChitChatUMO - Receives an event containing 'Hello Ross' and appends ', How are you?'

The GreeterUMO component is configured in the mule-config.xml file in src/samples/hello/conf. Components are defined using a mule-descriptor tag, which is configured as:

<mule-descriptor
    name="GreeterUMO"
    inboundEndpoint="stream://System.in"
    inboundTransformer="StringToNameString"
    outboundEndpoint="vm://chitchatter"
    implementation="org.mule.samples.hello.Greeter">
</mule-descriptor>

The mule-descriptor element defines the meta-data for a component, the metadata is used to tell Mule how to create and manage the component in the system.

Descriptor Properties

name

The name is used to identify the component in Mule.

inboundEndpoint

The inbound endpoint is what is used to receive inbound events for the
GreetUMO using the 'stream' transport provider.

inboundTransformer

The inbound transformer will be invoked before the GreeterUMO receives the event. In this case, the transformer converts the String (it receives from the stream provider) into a NameString object (expected by the GreeterUMO). The only purpose of doing this in the example is to demonstrate how mule will discover what method to invoke on the
GreeterUMO based on the transformer configured on it. Transformers are declared in the mule-config.xml at element /mule-configuration/transformers.

outboundendpoint

Once the GreeterUMO has been invoked Mule handles dispatching the next event. Mule dispatches the event to endpoint vm://chitchatter. This sends the event to an in-memory queue called chitchatter.

Implementation

The implementation is the 'key' by which to find the GreeterUMO instance in a configured container, this could be Spring or Pico, though if no container is configured mule will assume that the implementation value is a class name and instantiate it.

Now I have described the GreeterUMO, the ChitChatUMO should be easy to understand. The role of the ChitChatUMO is to add additional 'chitchat' to the current event. At this point our event reads 'Hello Ross'. The ChitChatUMO will turn that into 'Hello Ross, How are you?'. Its configuration looks like this:

<mule-descriptor
    name="ChitChatUMO"
    inboundEndpooint="vm://chitchatter"
    inboundTransformer="NameStringToChatString"
    outboundBound="stream://System.out"
    implementation="org.mule.samples.hello.ChitChatter">
</mule-descriptor>

To demonstrate Transformers further, the ChitChatUMO expects a ChatString, so we have a NameStringToChatString transformer that does the conversion from the NameString to a ChatString before the component receives the event. The event is received on vm://chitchatter, the endpoint on which the GreeterUMO dispatched its event.

We send our new 'ChitChat' event out using a 'stream' endpoint to System.out. Note that no outboundTransformer is configured because, by default the stream provider will call the toString() method on the object it receives and writes it to System.out. On our console we should see the following output -

Hello Ross, How are you?

Please enter your name:

Summary

Now we have come full circle. To recap -

  1. we triggered an inbound event by entering our name at the prompt on the console.
  2. This string was transformed into a NameString object that the GreaterUMO understands.
  3. The GreeterUMO pre-pended 'Hello' to the name string
  4. Mule handled the dispatching of the event to the ChitChatUMO.
  5. Mule also handled the transforming of the NameString to a ChitChatString expected by the ChitChatUMO.
  6. The ChitChatUMO added ', How are you?' to the current event string.
  7. Mule handled the dispatch of the event to the console

Mule Config Graph for the Hello World Examples

This is a configuration graph generated for the Hello World examples using the Mule Config Graph Tool.
(Click on the thumb image for a bigger picture)

Console Configuration

HTTP Configuration


Document generated by Confluence on Oct 03, 2006 09:23