Rama Kesara
Rama Kesara

Reputation: 94

Resolving mule app property referring to another property

I have multiple endpoints for different vendor's and we are differentiating it based on the userId for similar service operation and routing calls accordingly.

mule-app.properties

userIds=123,124,125

123.service.uri=http://google.com

124.service.url=http://yahoo.com

Can someone tell if there is a way to dynamically refer property using MEL and flowVariable holding userId value?

<flow name="test">
<http:listener config-ref="mylistenerconfig" path="test" doc:name="Request Listener" />

<set-variable variableName="userId" value="#[message.inboundProperties.userId]" />
<set-variable variableName="userServiceUri" value="${flowVars['userId'].service.uri}" />

<logger level="INFO" message="******* serviceUri=#[userServiceUri] ****" />

</flow>

I tried directly referring that value from message.inboundProperties.userId, referring it using a seperate variable - nothing works. Can someone suggest on how to achieve this?

Upvotes: 1

Views: 385

Answers (1)

David Dossot
David Dossot

Reputation: 33413

Load the properties files with Spring:

<util:properties id="muleAppProps"
    location="classpath*:mule-app.properties" />

Then you can dynamically refer to values in it with:

#[app.registry.muleAppProps[userId + '.service.uri']]

Assuming userId is a flow var that contains a value like "123"

Upvotes: 1

Related Questions