I am using this configuration expression.
<flow name="quartz">
<quartz:inbound-endpoint name="quartzstart" jobName="job1" repeatInterval="5000">
<quartz:envent=generator-job/>
<byte-array-to-string-transformer/>
<append-string-transformer message="Check Message"/>
<tcp:outbound-endpoint host="localhost" port="7778" connector-ref="protocol"/>
</flow>
It triggers every 5 seconds.
I was expecting the received message to be
Check Message
but the message I received was
(NullPayload)Check Message
How can I receive only "Check Message" ?
It seems that the toString of a null payload is returning (NullPayload).
You could set-payload with an empty string before the appender, or if this is your full logic just set-payload with "Check Message".
Related
I had started writing a simple Munit test for one of my flow. In the main flow. I have added a Munit set event to set some URI params to the mainflow.
<munit:test name="business-logic-test-suite-mainFlowTest" description="Test">
<munit:set-event cloneOriginalEvent="false">
</munit:set-event>
<set-payload value="#[payload]" doc:name="Set Payload"/>
<flow-ref name="mainFlow" doc:name="Flow-ref to mainFlow"/>
<munit:assert-payload-equals message="Output message is not matching excepted value #[payload]" expectedValue="#[payload]" doc:name="Assert Payload"/>
</munit:test>
When I try to run the test, the studio is throwing an error "Invalid content was found starting with element 'munit:set-event'". I tried some search on the internet and could not find anything related.
Any clue what could be missing ?
Thanks
If you want to set URI params, you can use Set Message component.
Another way to set the URI params is Message Properties component.
You can use this link for your reference.
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"/>
I have a flow where I want to evealuate an expression on the smtp subject attribute but always get mvel parse expression though the logger give me the right values.
<json:object-to-json-transformer doc:name="Object to JSON"/>
<logger message="MYRequestPayloadID #[json:RequestPayloadID] #[json:ResponseStatusCd]" level="DEBUG" doc:name="Logger"/>
<smtp:outbound-endpoint host="${mail.host}" to="${mail.to}" from="${mail.from}" subject="Error Response for PayloadID #[json:RequestPayloadID], Status #[json:ResponseStatusCd]" responseTimeout="10000" doc:name="SMTP />
I am not sure why in the subject #[json:RequestPayloadID] and #[json:ResponseStatusCd] evaluation fail though I get the data back in the logger . Thanks.
Expressions are not supported everywhere in Mule (alas): this is one place where it isn't.
You have to use message properties to set the subject dynamically:
<set-property propertyName="subject"
value="Error Response for PayloadID #[json:RequestPayloadID], Status #[json:ResponseStatusCd]" />
FTR json: is the old expression style, nowadays you should be using MEL instead: http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-JSONProcessing
I've a soap service flow which gets inbound request through <cxf:proxy-service>. I have a set payload right after it to get payload as String.
Here is my flow:
<flow name="soapService">
<http:inbound-endpoint address="${service.address}" exchange-pattern="request-response">
<cxf:proxy-service wsdlLocation="classpath:service.wsdl" namespace="http://pennmutual.com/services/mvi" service="MVIService" enableMuleSoapHeaders="false"/>
</http:inbound-endpoint>
<set-payload value="#[message.payloadAs(java.lang.String)]"/>
.
.
.
</flow>
<set-payload value="#[message.payloadAs(java.lang.String)]"/> works but if I replace it with <object-to-string-transformer>, it doesn't work.
How are these 2 inherently different?
UPDATE:
On replacing <set-payload value="#[message.payloadAs(java.lang.String)]"/> with <object-to-string-transformer> in my above flow, #[payload] gives com.ctc.wstx.sr.ValidatingStreamReader#429eb61a instead of the atcual XML
message.payloadAs(java.lang.String) relies on Mule's auto-transformation framework: I supposed it picks <xml:dom-to-xml-transformer> instead of <object-to-string-transformer> as the most appropriate transformer.
<flow>
<jms:inbound-endpoint queue="InputQueue"/>
<component class="MyComponent"/>
<choice>
<when expression="/Response/Status/Success" evaluator="xpath">
<jms:outbound-endpoint queue="LogInputQueue"/>
<jms:outbound-endpoint queue="SuccessQueue"/>
</when>
<when expression="/Response/Status/Error" evaluator="xpath">
<jms:outbound-endpoint queue="LogInputQueue"/>
<jms:outbound-endpoint queue="ErrorQueue"/>
</when>
<otherwise>
<jms:outbound-endpoint queue="LogInputQueue"/>
<jms:outbound-endpoint queue="ExceptionQueue"/>
</otherwise>
</choice>
</flow>
In this flow, MyComponent returns either success message as a response or error response or exception?
I need to log the original message from InputQueue in LogInputQueue in all the cases. How do I achieve this in my flow?
Did you mean to create a log file? In that case, you have to implement log4j using slf4j and use the line
<logger level="log_level" category="your_category" message="#[message:payload]"/>
where log_level is your desired logging level- "error", "debug", "info" etc...
your_category is your category of log defined in the log4j.properties file (it is optional actually)
and message="#[expression:value]" is your message to be logged given as an expression:scope:key combination. Scope is optional here.
Using log4j or slf4j you can log the payload.
[payload],we have logger component using this log payload in console.
Since, you need to send original message from InputQueue to LogInputQueue in all the cases, as you mentioned, what you need to do is :-
1. Remove <jms:outbound-endpoint queue="LogInputQueue"/> from all the cases in choice block
2. Store the original payload from InputQueue in a variable by placing it just after the JMS inbound endpoint
3. At the end of the flow, after the choice router, set the payload in set payload component from variable you stored the original payload
4. Now put <jms:outbound-endpoint queue="LogInputQueue"/> after your set payload component.
In this way you will able to send the original payload to the LogInputQueue as per your requirement.