JMS Transport relied in the payload to contain the body of a JMS Message, and used Mule’s outbound properties to customize the JMS Properties and Headers. With the new Mule 4 approach, the JMS 'publish' operation relies only on its input parameters to completely build the JMS Message to be published.
For example, if we wanted to send a high priority JMS Message with only a part of the payload in the body, and associate that Message to a group, we’ll need to:
<1>) Use transform to set the payload to what the Message body is expected to be.
<2>) Convert the resulting stream into a String to send it as a text message.
<3>) Set an outbound message property with priority as key to set the JMSPriority.
<4>) Set an outbound message property with JMSXGroupID as key to set the JMSXGroupID.
Mule 3 Example: Sending a prioritized Message as part of a Group
<flow name="JmsTransportOutbound">
<http:listener config-ref="HTTP_Listener_Configuration" path="/orders"/>
<dw:transform-message> (1)
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
order_id: payload.id,
supplier: payload.warehouse
}]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer/> (2)
<jms:outbound-endpoint queue="storage" connector-ref="Active_MQ">
<message-properties-transformer scope="outbound">
<add-message-property key="JMSXGroupID" value="#[message.inboundProperties."http.query.params".packageGroup]"/> (3)
<add-message-property key="priority" value="9"/> (4)
</message-properties-transformer>
</jms:outbound-endpoint>
</flow>
The same results can be achieved in Mule 4 using the JMS Connector with the following configuration:
Mule 4 Example: Sending a prioritized Message as part of a Group
<flow name="JMSConnectorPublish">
<http:listener config-ref="HTTP_Listener_config" path="/orders"/>
(2)
<jms:publish config-ref="JMS_Config" destination="storage" priority="9"> (3)
<jms:message> (1)
<jms:body>#[output application/json ---
{
order_id: payload.id,
supplier: payload.warehouse
}]</jms:body>
<jms:jmsx-properties jmsxGroupID="#[attributes.queryParams.packageGroup]"/> (4)
</jms:message>
</jms:publish>
</flow>
1) There’s no need of the transform component, since the body of the Message is created inline, thus the payload remains unmodified.
2) The object-to-string transformer was also removed, since the Connector can handle automatically the transformation output.
3) Priority is set as a parameter of the publish operation and doesn’t rely on the user knowing the exact key.
4) Group is set as part of the Message JMSX properties and doesn’t rely on the user knowing the exact header name.
As a summary, when publishing a Message in 3.x with the JMS transport, we relied on the MuleMessage payload, and outbound properties to configure the creation of the JMS Message, which meant a deeper knowledge of how the transport worked. In 4.x, the JMS Connector exposes every configurable element as a parameter in the scope were it belongs, thus exposing all the JMS functionality in a clearer way.