0
votes

Is it possible to intercept all the flows with Mule 4? Looks like MuleSoft has removed custom-interceptor, AbstractEnvelopeInterceptor, etc. from Mule 4.

I wanted to add some audit loggers like "Entering XYZ flow" and "Exiting XYZ flow". Instead of adding these loggers in each and every flow, I was thinking if this can be done with some common code.

2
Contacted MuleSoft support to get more information. MuleSoft confirmed that the replacement for interceptors is in development phase. So, as of May 7, 2018 we do not have interceptors available in Mule 4 but will be available soon.Sagar Chaudhari
That is not correct. See my answer for details.aled
Yep, MuleSoft support also gave me this link but unfortunately custom policies are not useful in my scenario.Sagar Chaudhari

2 Answers

0
votes

Interceptors are deprecated in Mule 4. See the documentation on migrating core components for details. You can use custom policies instead.

-2
votes

In Mule 4, to log a variable, the following approach can be taken:

<logger level="INFO" doc:name="My Var" message="#[vars.myVar]" category="values"/>

The expression inside #[ ] is an expression uses the DataWeave Expression Language.

To create more complex expressions to log variables, the function write() can be used:

<logger level="INFO" doc:name="My Var" message="#[' myVar = $(write(vars.myVar))']" category="values"/>

This will provide logging output as demonstrated:

org.mule.runtime.core.internal.processor.LoggerMessageProcessor: myVar = "the value" as String {class: "java.lang.String";, encoding: "UTF-8", mimeType: "application/java", raw: "the value" as String {class: "java.lang.String";}}

Note the following: The write function prints the variable myVar and its metadata (encoding, mime type, ray vaule, Java class)

The expression inside the #[ ] is a String. When we want to evaluate an expression inside a String we use $( ). For example this String: '$(1 + 1)' evaluates to '2'