Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Adding Message Processors to a Flow

This example shows how to add message processing components, in this example Logger and Echo, to a Flow. By doing so, you can perform custom logging in your Mule application. Logging is useful to introspect the current message and create logging events for your specific needs.

We introduce several new concepts here:

  • Message Processor - The Message Processor is the basic building block of all elements in Mule. These blocks can be glued together to create Mule flows. In this example, we use the Logger and Echo message processors.

  • Mule Expressions - Mule has a powerful, built-in expression language for querying request and response payloads and headers. We use an expression with the Logger component to extract some information and log something useful.

What You Will Learn

  • How to build on an existing Mule Flow in Mule Studio

  • How to use expressions to log request details

Watch the video

See this example built and run in Mule Studio

5 minutes

Build it Now!

Prerequisites

This examples requires that you have completed the previous example, Configuring an Endpoint.

Building the Example

\1. We continue editing the previous example, now adding a Logger component to the flow. Drag the Logger component from the palette to the canvas and placed it between the HTTP endpoint and Echo component:

image

\2. Double click the Logger component to edit its properties.

\3. In the Message field enter the following text: "About to echo #[MULE3EXAMPLES:payload]"

image

The #[MULE3EXAMPLES:payload] is a mule expression that is evaluated every time a request is made on this flow. The expression extracts the request payload. You can use Mule’spowerful expression language to execute XPATH, Groovy, and other code on the request or response header and payload.

Running the Example

\4. Right click the flow in the project tree and select Run As… → Mule Application

image Hot Deployment
There’s no need to stop the Mule application if it is still running from the previous example. The changes you made here are automatically "hot deployed" when you hit Save in the File menu or press CTRL+S.

image

\5. Next, open a browser and go to http://localhost:8081/echo. You should see the following in your browser:

image

\6. Now go back to Mule Studio and check the logs. You’ll see that the Logger wrote the request payload to the console window.

image

What Just Happened?

  • You just added a Logger message processor to your flow, which demonstrated how different processors can be sequenced in a Flow.

  • You used the #[MULE3EXAMPLES:payload] expression to log the payload of the request. The expression is evaluated for every message received at runtime.