I have a Mule flow, with a custom interceptor, which constructs an Object and forwards it to a JMS outboud endpoint. The JMS endpoint throws an exception trying to convert the Object to a JMS StreamMessage. What I want is for the endpoint to convert the Object to a JMS ObjectMessage, instead. How would that be done?
here's my flow;
<spring:beans>
<spring:bean id="connectionFactoryFactory" name="connectionFactoryFactory"
class="ConnectionFactoryFactory">
<spring:property name="properties">
<spring:props>
<spring:prop key="imqAddressList">mqtcp://localhost:30001/jms</spring:prop>
<spring:prop key="imqReconnectAttempts">-1</spring:prop>
</spring:props>
</spring:property>
</spring:bean>
<spring:bean id="connectionFactory" name="connectionFactory"
factory-bean="connectionFactoryFactory" factory-method="createConnectionFactory" />
</spring:beans>
<jms:connector name="JMSConnector" connectionFactory-ref="connectionFactory"
specification="1.1" doc:name="JMS" />
<flow name="Request" doc:name="Request">
<quartz:inbound-endpoint responseTimeout="10000"
doc:name="InfoRequest" jobName="InfoRequest" repeatInterval="5000">
<quartz:event-generator-job />
</quartz:inbound-endpoint>
<custom-interceptor class="StateRequest"/>
<jms:outbound-endpoint connector-ref="JMSConnector"
doc:name="JMS" topic="requests"/>
</flow>
I have also tried adding an Object to JMS Message Transformer;
<jms:object-to-jmsmessage-transformer returnClass="javax.jms.ObjectMessage" name="Object_to_JmsMessage" doc:name="Object to JmsMessage"/>
<jms:outbound-endpoint connector-ref="JMSConnector"
doc:name="JMS" topic="requests" transformer-refs="Object_to_JmsMessage"/>
Serializable
? – David DossotObjectMessage
s rely on Java Serialization and thus are tightly coupling, something you do not want in a messaging environment. According to the source code, if the Mule Message payload is aSerializable
(and not aList
nor aString
), Mule will automatically create anObjectMessage
without the need to configure any transformer manually... – David DossotList
so Mule serializes it as aStreamMessage
. Unfortunately this behavior is in a static class so it's hard to swap with another one. Either create your own JMS ObjectMessage from code or subclassAbstractJmsTransformer
to create your own flavor ofObjectToJMSMessage
that would callJmsMessageUtils.serializableToMessage
for payloads of typeRequest
. – David Dossot