Search code examples
parametersmulemule-flow

Mule ESB How to define variables UPFRONT


The quick, short shot:

is there a way to set UPFRONT the expected input parameters the flow [will receive]? Have to mention that the intention is to leverage the Anypoint Studio's Metada pane, which shows the "output variables" (no matter if they are payload, or flow, or session variables).

The elaborated, with contextual explanation:

I'm a 'lazy' programmer. I've become pretty fond on those auto-complete features found in [most of] the IDEs. I haven't to mention how I was satisfied when I found the Mule Anypoint Studio had that auto-complete and the 'meta-data', which shows the things that are created.

But when I started building flows, I start wondering with myself if there was some way to get the incoming parameters (I mean those input parameters that, for example, a JMS-subscribing flow is expecting to receive).

Perhaps a sample case will be easier to understand. Sample XML:

<flow name="flow.JMSSubscriber">
    <jms:inbound-endpoint topic="/test" connector-ref="Active_MQ_PasswordReset" doc:name="JMS"/>
    <flow-ref name="flow.SetVariables" doc:name="flow.SetVariables"/>
    <logger level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="flow.SetVariables">
    <set-variable variableName="whatever" value="#[&quot;value&quot;]" doc:name="Variable"/>
</sub-flow>

You can find that clicking on the flow reference 'flow.SetVariables', and looking into the Metadata pane (assuming you're on the standard 'Mule Design' perspective, this pane is located at the right lower corner of the window), click on the 'Output' tab, and voilà: the 'whatever' Flow Variable [set in the "flow.SetVariables" subflow] is there.

Here is the URL of the screen I'm describing: https://i.sstatic.net/raSYc.png .

My initial attempts were setting up a subflow that mocked the creation of those varibles, using 'set-variable'. That is acceptable when you have just a handful of variables (my hand has only five fingers, thus five variables is the limit) or when the parameters are flat (not nested, such as '/quantity/value, /quantity/UOM', or '/price/value , /price/currency').

But talking seriously: 6-months later, I won't remember what are the input parameters that flow was expecting. Or, if you're dealing with a structured, multi-level-nested XML input, like those OAGIS XMLs, it gets a real pain to set that up (what about adding 'that' simple thing to the structure?)

The idea of doing such this is also to easy the maintenance on those flows. Other folks will come to learn Mule and maintain these flows. Thus, I'd like to make their lives a easier (not to mention that this will help them to do the things on their own)

Thus my question: is there a way to set UPFRONT the expected input parameters the flow [will receive]? Have to mention that the intention is to leverage the Anypoint Studio's Metada pane, which shows the "output variables" (no matter if they are payload, or flow, or session variables).


Solution

  • On the left side of the properties view there is a metadata tab. There you can specify input/output metadata for the message processor.

    If they are structured types (xml, json, etc) you can either use schema files or sample data (and it will try to infer the schema)

    enter image description here