Mule如何使jms出站端点使用ObjectMessage而不是StreamMessage

时间:2013-03-12 15:39:07

标签: mule mule-studio

我有一个Mule流,带有一个自定义拦截器,它构造一个Object并将其转发到JMS outboud端点。 JMS端点在尝试将Object转换为JMS StreamMessage时抛出异常。我想要的是端点将Object转换为JMS ObjectMessage。怎么做?

这是我的流程;

<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>

我也尝试过将一个Object添加到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"/>

1 个答案:

答案 0 :(得分:0)

由于Request extends LinkedList<RequestId> implements Serializable,Mule会自动将此类型转换为StreamMessage

不幸的是,这种行为属于静态类,因此很难与另一个进行交换。从代码或子类ObjectMessage创建自己的JMS AbstractJmsTransformer,以创建自己的ObjectToJMSMessage风格,为JmsMessageUtils.serializableToMessage类型的有效负载调用Request