Docs: Never Leave Home Without Em

September 25 2014


Given the ever broadening capabilities and functionality of Anypoint Platform, even the most experienced MuleSoft developers will be challenged to remember all the features and tricks the product suite provides. Especially on fast-paced implementations, one can easily be caught up with the ebbs and flows of the daily project tasks and ironically, forget to leverage that one tool that can really help with productivity – documentation. In , we often get questions that our documentation often does a better job of answering. There are dozens of examples; we have picked just a couple below that we’ve been asked lately.

Session Variable

The first example is about session variable. Most developers are well aware that session variables persist through the entire message lifecycle. However, some often forget about this part in the documentation:

… a variable that is tied to the current message for its entire lifecycle, across multiple flows, applications, and even servers…”

The example here demonstrates how session variables can travel across servers. There are two independent Mule applications. The first one sets a session variable, then publish it to a JMS queue.

We are using but all other JMS brokers behave the same way. The second application receives messages from the same queue.

Note that the applications and ActiveMQ can reside on three different servers, in three different networks. As shown in the screenshots below, the session variable was propagated across.

This is a powerful capability for transmitting information across, at the same time, one must be careful with what information is being shared when sending payloads outbound. Below is a screenshot of how the message will appear in the JMS admin console.

Anypoint Connectors

The second example is around Anypoint Connectors. For many Anypoint Connectors, connection parameters can be passed in at the core operation calls level, in addition to setting it in the configuration element. This is a very useful feature that can significantly streamline your Mule applications if you need to process messages the same way from the same endpoints but with different credentials. Using the Connector as an example, the document states:

Connection Parameters: These are only required if you didn’t specified them at the configuration element. They are also useful for overriding the values of the configurations or even if you need to extract them from the Mule message since they support expression evaluation.

The following is a simple Mule app to demonstrate this handy feature. In the app, we use the same flow to retrieve information from two different organizations.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:context="" xmlns:http="" xmlns:sfdc="" xmlns:json="" xmlns:tracking="" xmlns="" xmlns:doc=""
	xmlns:spring="" version="EE-3.5.1"
    <sfdc:config name="" doc:name="Salesforce"/>
    <context:property-placeholder location=""/>
    <flow name="sfdc-mt-blog-demoFlow1" doc:name="sfdc-mt-blog-demoFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="start-demo" doc:name="HTTP"/>
        <expression-transformer expression="#[[['user':'${sfdc.user1}', 'password':'${sfdc.pass1}', 'token':'${sfdc.token1}'],['user':'${sfdc.user2}', 'password':'${sfdc.pass2}', 'token':'${sfdc.token2}']]]" doc:name="Mock multiple credentials"/>
        <collection-splitter doc:name="Collection Splitter"/>
        <flow-ref name="shared-sfdc-logic" doc:name="shared-sfdc-logic"/>
        <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
        <http:response-builder contentType="application/json" doc:name="HTTP Response Builder"/>
    <flow name="shared-sfdc-logic" doc:name="shared-sfdc-logic">
        <sfdc:get-user-info config-ref="Salesforce" username="#[payload.user]" password="#[payload.password]" securityToken="#[payload.token]" doc:name="Get user info"/>
        <expression-transformer expression="#[['organization':payload.organizationId, 'user':payload.userName, 'full name':payload.userFullName, 'email':payload.userEmail]]" doc:name="User and Org Info"/>
        <logger message="SFDC response #[payload]" level="INFO" doc:name="Logger"/>

Using this pattern, a Mule app can easily store the credentials in a database or encrypted file, and dynamically retrieve data from as many organizations as needed, as shown in the results:

These are just a couple of examples of the many things that we developers encounter daily that our documentation does a really good job of addressing. So whether you are just starting on the journey of Mule implementation or already way down the road, please keep our documentation in mind. It can significantly smoothen your ride along the way!

We'd love to hear your opinion on this post