Mule message-properties-transformer example


In this article we will see how to explicitly add an outbound propertie. Before we start we must first understand the definition of a message property and how it fits in the overall message structure.

  1. A Mule message contains the following parts:
  2. Metadata – Scope based properties
  3. Payload – Main data
  4. Named attachments (inbound, outbound)- Multipart message
  5. Exception Payload – Holds any exception during the processing of the event

Next we need to know the difference between an inbound property and an outbound property.

Inbound properties come into the flow as part of the inbound message and they are immutable. As soon the message passes out of the flow, either into another flow or application, the inbound properties ceases to exist.
In contrast outbound properties are mutable, they are set during the course of a flow or in the response phase. As soon as the message leaves the current flow and enters into a new flow or returns to the application, the outbound properties of previous flow become inbound properties of the message.

In this article, we will show you how to manually set an outbound property manually using a message properties transformer in the flow.

A Message Properties Transformer lets you add, rename, or delete message properties. In this example, we will add a new outbound property, of course you can apply it in any scope (invocation, outbound, session or application) you want.

<message-properties-transformer scope="outbound">
    <add-message-property key="test" value="test"/>

You can also use it to propagate an inbound property to an outbound.

<add-message-property key="foo" value="#[header:INBOUND:someInboundProp]"/>

Below we are setting an http outbound property:

<add-message-property key="Content-Type" value="text/plain;charset=UTF-8"/>

Delete a message property:

<delete-message-property key="someProperty"/>

Rename a message property:

<rename-message-property key="someProperty1" value="someProperty2"/>

In the below flow, the message sent to vm://in is the passed on to an outbound point vm://out which takes it to next flow out-flow. A static message “Response from out” is appended to the input. The message returns to the first flow in-flow where message ” – appended to out response” is appended and returned as the response. In the response phase we add a new outbound property. Since the exchange pattern used is “request-response”, the flow response is returned to the application. The property added in outbound scope is now accessible in inbound scope.

System.out.println("Inbound property value of 'test':" + response.getProperty("test", PropertyScope.INBOUND));


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns=""
      xsi:schemaLocation="    ">

    <flow name="in-flow">
        <vm:inbound-endpoint path="in" exchange-pattern="request-response"/>
        <vm:outbound-endpoint path="out" exchange-pattern="request-response">
                <message-properties-transformer scope="outbound">
                    <add-message-property key="test" value="test"/>
                <append-string-transformer message=" - appended to out response" />

    <flow name="out-flow">
        <vm:inbound-endpoint path="out" exchange-pattern="request-response"/>
            <return-data>Response from out</return-data>



package com.javarticles.mule;

import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.api.context.MuleContextBuilder;
import org.mule.api.context.MuleContextFactory;
import org.mule.api.transport.PropertyScope;
import org.mule.config.DefaultMuleConfiguration;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextBuilder;
import org.mule.context.DefaultMuleContextFactory;
import org.mule.module.client.MuleClient;

public class MuleMessagePropertiesTransformerExample {
    public static void main(String[] args) throws Exception {
        DefaultMuleConfiguration dmc = new DefaultMuleConfiguration();
        SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder(
        MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
        MuleContextFactory contextFactory = new DefaultMuleContextFactory();
        MuleContext ctx = contextFactory.createMuleContext(configBuilder,
        try {
            MuleClient muleClient = new MuleClient(ctx);
            MuleMessage response = muleClient.send("vm://in", "some message", null);        
            System.out.println("Response: " + response.getPayloadAsString());
            System.out.println("Inbound property value of 'test':" + response.getProperty("test", PropertyScope.INBOUND));
        } finally {


Response: Response from out - appended to out response
Inbound property value of 'test':test            

Download the source code

This was an example about mule adding properties to the message.

You can download the source code here:

Comments are closed.