I have written a custom Anypoint connector (using devkit), and want it to set Inbound properties, much like the Mule HTTP connector does. MuleMessage however, does not seem to have facility to do this.
How does one mimic this behavior?
Inbound properties are immutable, It can be achieved via the MuleMessage https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty(java.lang.String, java.lang.Object, org.mule.api.transport.PropertyScope)
However, unless your connector operation is a Message Source I wouldn't add inbound properties and instead use outbound properties.
You need to use
MuleMessage message = eventContext.getMessage();
message.setProperty("key","value",PropertyScope.INBOUND);
You can refer the API :-https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/MuleMessage.html#setProperty
https://www.mulesoft.org/docs/site/3.3.0/apidocs/org/mule/api/transport/PropertyScope.html
Related
can anyone explain what is Service Data Object(SDO) and Service Message Object(SMO)?
Questions:
1. what is the purpose of SDO and SMO?
2.how it works?
These concepts aren’t used with Mule, they seem to come from IBM. https://www.ibm.com/support/knowledgecenter/SSFTN5_8.5.7/com.ibm.wbpm.main.doc/topics/cwesb_sca_smo2.html
The equivalent of the SMO in Mule is the Mule Event which you can read about here: https://docs.mulesoft.com/mule-runtime/4.1/about-mule-event
A Mule event contains the core information processed by the runtime. It travels through components inside your Mule app following the configured application logic.
It’s basically an abstraction layer so you don’t have to deal with different protocols and transports.
A Mule Event is composed of these objects:
A Mule Message contains a message payload and its associated attributes.
Variables are Mule event metadata that you use in your flow.
A Http POST for example would be represented as an event.
The event payload would be the body data of the http request
Where as the http headers such as content-type would be attributes on the event.
Same for JMS. The message body would be the payload and the jms header would be attributes.
As for SDO, each SMO has an SDO. This is very specific to that IBM article and not relevant in Mule. But from what I understand it basically allows you to access your heterogenous business data in a common way. I guess Dataweave in Mule accomplishes this as Dataweave is the transformation and expression language in Mule, it allows you to query and transform data in the same way regardless of the data type, xml, Json, CSV and so on.
In this sub-flow, how can I access from the http connector (red area) the inbound properties available at green marked area.
The scope of the inbound property is only just after the inbound endpoint or the source endpoint.
Here you should copy your inbound properties to the "flowVars" and then use it across the flow
#[flowVars.paramerterName = message.inboundProperties.'http.query.params'.parameterName]
Please make note if you want to access the HTTP properties, the syntax MEL format will be different for the Mule latest version and old version. The above one is valid for the latest Mule version and the syntax to access any property like below
#[message.inboundProperties.'http.query.params'.cityname]
where as in previous versions
#[message.inboundProperties['propertyName']].
This will depend on your inbound message source, but assuming it is an HTTP connector, use the MEL expression to access the inbound property http.query.params
#[message.inboundProperties['http.query.params']
The inbound message object is nothing but a HashMap of key-value pairs - best would be to use the debugger and select the keys you would like to access.
Here is the documentation for the Mule message, there you will find the description for the different kind of variables and properties. Inbound properties should be propagated from the main flow to the sub-flow and should still be available after the choice, excepting the case where you overwrite them or when there is an outbound-endpoint, which would overwrite them too.
Is it possible to use mule message properties (like payload and flowvars) in a Mule Management Console notification body or subject?
I think it's not possible.
You can only use the properties exposed by mule, as explained here:
http://www.mulesoft.org/documentation/display/current/Defining+SLAs+and+Alerts#DefiningSLAsandAlerts-PropertiesUsedinAlertExpressions
Maybe using a Management Script, but there is no much info about it (the links to the javadoc are broken)
http://www.mulesoft.org/documentation/display/current/Scripting+Examples#ScriptingExamples-AlertingExamples
Yes you can use it. Mule provide various properties common to all alerts from class com.mulesoft.console.alert.RaisedAlert that can be used in defining the certain values such as
Flow identifier
Flow name
You may refer to mule documentation for it
https://docs.mulesoft.com/mule-management-console/v/3.7/defining-slas-and-alerts#DefiningSLAsandAlerts-PropertiesUsedinAlertExpressions
How do i retrieve the values of MULE Headers like X-MULE_ROOT_MESSAGE_ID and X-MULE_SESSION. When I try to use them from #[message.inboundProperties[X-MULE_ROOT_MESSAGE_ID] I am not able to get values. How do I also get the client IP address from Mule HTTP inbound end point?
These X- headers are extracted and set directly as message properties or a session object.
So you'll find the content of X-MULE_ROOT_MESSAGE_ID by calling getMessageRootId() on the MuleMessage and you'll get the values serialized in X-MULE_SESSION directly in the current MuleSession object.
Read this How to correctly use Mule remote client address property to learn more about the remote IP address.
#[header:INBOUND:MULE_CORRELATION_ID]
you can get like this.
if you need to retrive in the java, you can get all the inbound as map (inbound properties) from message context.
Use Mule expressions to get the mule session id
I have a MuleClient that sends a message to a Mule flow like below but I dont see properties reflected in the mule flow in response section, what scope should I make the properties to be?
MuleMessage msg = new DefaultMuleMessage();
Map<String,Object> propertiesMap = new HashMap<String,Object>();
propertiesMap.put("name", "hello");
msg.addProperties( propertiesMap, PropertyScope.INVOCATION);
then in the flow I tried to access this property like this
message.getInvocationProperty("name")
and it returns null... What am i missing?
If you send a message to a flow using a VM (or any transport) endpoint, invocation properties will not be propagated.
You need to place the properties in the outbound scope: they will arrive in the inbound scope out of the inbound endpoint of the flow.
Since you are sending the MuleMessage to Connector (ie. inbound vm ), Invocation properties not available in your flow. MessageProperties in outbound scope wil be modified into inbound scope. so use the outbound scope, in your flow access like #[message.inboundPrperties['name']]