Mule : Hello World Example
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 Running the ApplicationPrerequisitesTo run you will need the following -
Optional
Running
- Walk throughThe 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 -
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 PropertiesnameThe name is used to identify the component in Mule. inboundEndpointThe inbound endpoint is what is used to receive inbound events for the inboundTransformerThe 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 outboundendpointOnce 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. ImplementationThe 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: SummaryNow we have come full circle. To recap -
Mule Config Graph for the Hello World Examples
|
![]() |
Document generated by Confluence on Oct 03, 2006 09:23 |