如何将JMS消息转换为DataMapper的JSON

时间:2014-11-17 09:06:43

标签: jms mule

我通过JMS将以下json消息发送到流:

[{" salesOrderId":" 00001-2-3"," saleName":" Car Sale","状态":"处理"},{" salesOrderId":" 00004-5-6"," saleName":&#34 ;房屋销售","状态":"处理"}]

这是我的策略:

    <flow name="integration-consumer-client2" doc:name="integration-consumer-client2">
    <jms:inbound-endpoint queue="client2.queue" connector-ref="Active_MQ" doc:name="JMS"/>
    <logger message="Consumes Client 2 = #[payload]" level="INFO" doc:name="Logger"/>
    <logger message="Client 2 Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
    <vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>
</flow>
<flow name="integration-consumer-client" doc:name="integration-consumer-client">
    <jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="client1.queue">
    </jms:inbound-endpoint>
    <logger message="Consumes Client = #[payload]" level="INFO" doc:name="Logger"/>
    <logger message="Client Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
    <vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>      
</flow>  
<flow name="integration-flow" doc:name="integration-flow">
    <vm:inbound-endpoint path="response" doc:name="VM">
         <message-properties-transformer>
            <add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" />
        </message-properties-transformer>
        <collection-aggregator/>
    </vm:inbound-endpoint>
    <logger message="after vm = #[payload]" level="INFO" doc:name="Logger"/>
     <request-reply doc:name="Request-Reply">
        <jms:outbound-endpoint queue="queue.validation" connector-ref="Active_MQ" doc:name="JMS">
             <jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
        </jms:outbound-endpoint>
        <jms:inbound-endpoint queue="queue.validation.response" connector-ref="Active_MQ" doc:name="JMS"/>
    </request-reply>
    <logger message="Siebel Response in ESB = #[payload]" level="INFO" doc:name="Logger"/>
</flow>

因此聚合了两个消费者消息,然后使用JMS通过请求回复将其发送到另一个流。在那个流程中,消息来自as [{&#34; salesOrderId&#34;:&#34; 00001-2-3&#34;,&#34; saleName&#34;:&#34; Car Sale&#34;,&#34; status&#34 ;:&#34;处理&#34;},{&#34; salesOrderId&#34;:&#34; 00004-5-6&#34;,&#34; saleName&#34;:&#34; House Sale& #34;&#34;状态&#34;:&#34;处理&#34;}]

和流程:

    <jms:activemq-connector name="Active_MQ" username="admin" password="admin" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<data-mapper:config name="JSON_To_JSON" transformationGraphPath="json_to_json.grf" doc:name="JSON_To_JSON"/>
<flow name="validation-flow" doc:name="validation-flow">
    <jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="queue.validation" >
        <jms:jmsmessage-to-object-transformer doc:name="JMSMessage to Object"/>    
    </jms:inbound-endpoint>

    <logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
    <data-mapper:transform config-ref="JSON_To_JSON" doc:name="JSON To JSON"/>
    <logger message="inside siebel after mapper = #[payload]" level="INFO" doc:name="Logger"/>
</flow>

我想通过mapper发送数据,因为我想将状态更改为&#34; Complete&#34;。但是在json到json mapper之后,结果是[B @ 2b9f82b。如何将jms消息转换为对映射器更具可读性?

1 个答案:

答案 0 :(得分:1)

你拥有的是一个完全有效的bytearray。您可以使用对象到字符串转换器再次将其转换为String,或者甚至更好地将字节数组转换为字符串转换器。