Mule Invocation Scoped Property


In this article we will look into example of invocation scope. The scope of an inbound property ends where theĀ outbound endpoint beginsĀ whereas this is not the case with the invocation scoped property.

Add invocation scoped property

In the below mule context, we use <message-properties-transformer> to add a message property with invocation scope. We then post the message to an outbound endpoint and verify the invocation property in the second flow.

Life of invocation scope

You will see that the invocation scoped property is only available within the flow it is added. You won’t be able to access when the message traverses to another flow as a result of an outbound endpoint.


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="" xmlns=""
	xmlns:xsi="" xmlns:vm=""
	xmlns:spring="" xmlns:test=""
	<flow name="flow1">
		<vm:inbound-endpoint path="in"
			exchange-pattern="request-response" />
		<message-properties-transformer scope="invocation">
			<add-message-property key="invocation_property"
				value="Invocation Example" />
		<vm:outbound-endpoint path="out_res"
			exchange-pattern="request-response" />
		<custom-processor class="com.javarticles.mule.PrintInvocationProperty">
			<spring:property name="property" value="invocation_property" />

	<flow name="flow2">
		<vm:inbound-endpoint path="out_res"
			exchange-pattern="request-response" />
		<custom-processor class="com.javarticles.mule.PrintInvocationProperty">
			<spring:property name="property" value="invocation_property" />


Access Invocation scoped property

Below is the custom processor that retrieves the invocation property and prints.


package com.javarticles.mule;

import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
import org.mule.api.processor.MessageProcessor;

public class PrintInvocationProperty implements MessageProcessor {
    private String property;

    public String getProperty() {
        return property;

    public void setProperty(String property) { = property;

    public MuleEvent process(MuleEvent event) throws MuleException {
        Object invocationProperty = event.getMessage().getInvocationProperty(property);
        System.out.println(getProperty() + ": "+ invocationProperty);
        return event;

Mule invocation scoped property example

We start the flow by posting a message to inbound endpoint vm://in. After the response, we verify whether the invocation property still exists.


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.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 MuleInvocationScopeExample {
    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);
            sendMsgAndVerifyProperties("vm://in", ctx, muleClient);           
        } finally {
    private static void sendMsgAndVerifyProperties(String endpointUri, MuleContext ctx,
            MuleClient muleClient) throws Exception {
        System.out.println("send message to " + endpointUri);
        MuleMessage response = muleClient.send(endpointUri, "Hello", null);   
    private static void printInboundProperties(MuleMessage response) throws Exception {
        System.out.println("Verify properties after response");
        System.out.println("Response: " + response.getPayloadAsString());
        System.out.println("invocation_property: " + response.getInvocationProperty("invocation_property"));

As you can see from the below output the invocation scoped property is simply a flow variable as it can only be accessed within a flow. The invocation property is not available when the message traverses to the second flow but is available when it comes back from the outbound endpoint to the first flow.

Use invocation properties if you need to a property that you plan to use in multiple places within the same flow.


send message to vm://in
invocation_property: null
invocation_property: Invocation Example
Verify properties after response
Response: Hello
invocation_property: null

Download the source code

This was an example of inbound scoped property.

You can download the source code here:

About Author

Ram's expertise lies in test driven development and re-factoring. He is passionate about open source technologies and loves blogging on various java and open-source technologies like spring. You can reach him at [email protected]

Comments are closed.