i want to set value in mule-app.properties again. Is there anyway to do this?
Example in mule-app.properties: hostip=192.168.1.116 , in my flow i want to change it become 192.168.1.117
It is very easy. In mule-app.properties you defines properties as you mentioned.
In your flow you use a property placeholder to use the value of that property in a flow or in a configuration. It will be evaluated at deployment time.
Example:
<http:listener-config name="HTTP_Listener_Configuration"
host="${host}" .../>
<flow name="someFlow">
<logger message="host: ${host}" level="INFO" doc:name="Logger" />
Related
I need to retrieve the value set in session variable in flow1 to flow2. The code I've written looks like this :
<flow name="demo1Flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="demo" doc:name="HTTP"/>
<set-session-variable variableName="name" value="balwant" doc:name="Session Variable"/>
<logger message="Inside demo1 #[sessionVars.name]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/test" method="GET" doc:name="HTTP"/>
</flow>
<flow name="demoFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger message="Inside demo flow #[sessionVars['name']]" level="INFO" doc:name="Logger"/>
</flow>
With the above code I'm not able to get the value from session variable which was set in demo1Flow to demoFlow. The output for this flow I'm getting is :
INFO 2017-03-07 12:55:28,455 [[demo].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Inside demo1 balwant
INFO 2017-03-07 12:55:28,536 [[demo].HTTP_Listener_Configuration.worker.02] org.mule.api.processor.LoggerMessageProcessor: Inside demo flow null.
As the documentation says that value in Session variable is accessible across the session in different flows, but here that is not happening :(. Not sure what is the reason.
Referring Session Variable Transformer Reference documentation, the Session Variable persist for the entire message lifecycle, regardless of transport barriers, except for the HTTP Connector which doesn’t propagate them.
They are two independent flows which process messages based on different input paths, although you are calling using http requester from flow1,second has its own scope.
For every flow it's scope begins with its inbound.
As there is no relationship between those two flows, you can't access anything from flow1 in the other. If you want that variable you can set as outbound property then it will become inbound property to the second flow. Otherwise you can set as uri parameters.
Regards,
Mallesh
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?
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"
The message enricher documentation uses a term "variable" for example
<flow name="orderProcessingFlow">
<inbound-endpoint ref="orderEndpoint"/>
<enricher target="#[variable:state]">
<outbound-endpoint ref="stateLookup"/>
</enricher>
<outbound-endpoint ref="orderStep2"/>
</flow>
I did not find any documentation on that keyword, I can figure out it basically adds a flow variable, but is there anything more to it ? (without keyword variable you get a exception)
Also none of the examples in the documentation refer to enriching "message headers" -- My assumption is that message headers implies outbound properties is that correct ?
If the same flow were to add a outbound property how would it look (this works based on my tests)
<flow name="orderProcessingFlow">
<inbound-endpoint ref="orderEndpoint"/>
<enricher target="#[message.outboundProperties.var]">
<outbound-endpoint ref="stateLookup"/>
</enricher>
<outbound-endpoint ref="orderStep2"/>
</flow>
#[variable:state] is the old expression syntax, it's deprecated and replaced by MEL since 3.3. I think the MEL equivalent is #[flowVars.state]
Similarly, message "headers" is obsolete lingo. You have message properties with different scopes (inbound, outbound, flow/invocation and session).
And yes the only properties you can set in a flow are outbound properties (inbound ones are set by endpoints).
I'm not sure, how can we extract the flow-name and message-processor Name through MEL. For example I have multiple message processor. For logging, i need to extract the flow Name and Message-processor, so that I can find out transaction has crossed this particular flow and its message processor. Is there any simple way to find out. Please guide me. Please find the screenshot below. Here i need to Extract - set payload and its flowName (flow1)
Thanks in advance.
For mule 3.8+ version onwards #[flow.name] don't work.
Use #[mule:context.serviceName] expression in logger or component to extract the name of the flow
I know this post is old but I have been trying to find a way to do this in MEL for error handling emails.
For the flow name you can use #[exception.event.flowConstruct.name]
for the failing message processor you can use #[exception.failingMessageProcessor].
Both of these work in MEL without the need to use an flowVar.
Please note however, that the failing processor does not always come back with a value but comes back with null, I'm not sure why.
You can extract the flow-name with MEL : #[flow.name]
<flow name="name" doc:name="name">
<http:inbound-endpoint address="http://localhost:8090/resources" doc:name="HTTP" />
<logger message="name of flow: #[flow.name]" level="INFO" doc:name="Logger"/>
<set-payload value="name" doc:name="Set Payload"/>
</flow>
or
flowConstruct.getName() in a Message Processor
Two ways to acthive this (from current flow name)
First one is -
<logger message="Current flowName: #[flow.name]" level="INFO" doc:name="Logger"/>
and the second one is -
<logger message="Current flowName: #[context:serviceName]" level="INFO" doc:name="Logger"/>
In trying to restore the original payload in a message, I ran into this issue that confused me regarding the scope of a mule message. Given the mule config below, I initially assumed that the payload received at the test.Name vm endpoint was going to be restored at the end of the flow (see 1. and 2. in the config):
<mule ...>
<vm:endpoint name="replacePayloadWithFoo.Name"
path="replacePayloadWithFoo.Path" />
<flow name="test">
<vm:inbound-endpoint name="test.Name" path="test.Path"
exchange-pattern="request-response" />
<!-- 1. Down below, I wanted to restore the payload at this point -->
<expression-transformer evaluator="string"
expression="bar" />
<outbound-endpoint ref="replacePayloadWithFoo.Name"
exchange-pattern="request-response" />
<!-- 2. The transformer below does not restore the payload at 1. -->
<expression-transformer evaluator="groovy"
expression="message.originalPayload" />
</flow>
<flow name="replacePayloadWithFoo">
<inbound-endpoint ref="replacePayloadWithFoo.Name"
exchange-pattern="request-response" />
<expression-transformer evaluator="string"
expression="foo" />
</flow>
</mule>
However, it seemed as though the message that entered the test flow ended at the replacePayloadWithFoo outbound endpoint. The transformer at 2. leaves "foo" as the payload.
What's the scope of the mule message?
In passing, the scripting reference documentation indicates that there is a binding for originalPayload in groovy scripts. However, if the transformer at 2. is replaced with
<expression-transformer evaluator="groovy" expression="originalPayload" />
I get an exception:
org.mule.api.expression.RequiredValueException: Expression Evaluator "groovy"
with expression "originalPayload" returned null but a value was required.
What could be the issue?
Thanks
Any outbound interaction, unless performed through an enricher, will affect the current in-flight message. This is why the call to replacePayloadWithFoo replaces the original message with the result of the outbound interaction.
This said, I can not explain the discrepancy between:
<expression-transformer evaluator="groovy" expression="message.originalPayload" />
and:
<expression-transformer evaluator="groovy" expression="originalPayload" />
because they both rely on:
event.getMessage().getPayload()