我在 IBM MQ 上发布 MapMessage 并使用 SI 我正在接收该消息(使用 jms:inbound-gateway)。我想将此 Map 转换为一个对象,因此我使用的是 map-to-object-transformer。当我收到一条消息并且转换器尝试将此地图转换为一个对象时,我得到了 ClassCastException。
MapMessage 发布者
public void sendMapMessage(){
jmsTemplate102.send(sendQueue,
new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return getEventMap(session);
}
public Message getEventMap(Session session){
MapMessage mapMsg = null;
try {
mapMsg = session.createMapMessage();
mapMsg.setStringProperty("batchId", "123987");
mapMsg.setStringProperty("eventType", "ABCD");
mapMsg.setStringProperty("client", "CORP");
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapMsg;
}
});
}
JMS 入站网关
<int-jms:inbound-gateway id="jmsInGateway" request-destination="receiverQueue"
request-channel="events"
concurrent-consumers="1"
max-concurrent-consumers="4"
acknowledge="auto"
/>
<int:channel id="etlEvents"/>
<int:map-to-object-transformer input-channel="etlEvents" output-channel="etlEvents" ref="etlEvent"/>
例外
JMS Message class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d5120414344534430513720202020537502dd20130f02
JMSTimestamp: 1404142195240
JMSCorrelationID:null
JMSDestination: null
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_PutDate:20140630
JMSXAppID:Websphere MQ Client for Java
JMS_IBM_Format:MQSTR
JMS_IBM_PutApplType:28
JMS_IBM_MsgType:8
JMSXUserID:mqcls1
JMS_IBM_PutTime:15295524
JMSXDeliveryCount:1
<map></map>] to integration Message payload [<map></map>]
2014-06-30 10:48:13,356 DEBUG [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] channel.DirectChannel - preSend on channel 'etlEvents', message: [Payload String content=<map></map>][Headers={JMS_IBM_Format=MQSTR , errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@581bce9a, jms_timestamp=1404142195240, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@581bce9a, JMSXUserID=mqcls1 , JMS_IBM_PutApplType=28, JMS_IBM_MsgType=8, JMS_IBM_PutDate=20140630, jms_messageId=ID:414d5120414344534430513720202020537502dd20130f02, JMS_IBM_PutTime=15295524, JMSXDeliveryCount=1, jms_redelivered=false, priority=4, JMSXAppID=Websphere MQ Client for Java, id=f8aacfea-e655-e19d-1b7f-fd99389bf095, timestamp=1404139693356}]
2014-06-30 10:48:13,356 DEBUG [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] transformer.MessageTransformingHandler - org.springframework.integration.transformer.MessageTransformingHandler#0 received message: [Payload String content=<map></map>][Headers={JMS_IBM_Format=MQSTR , errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@581bce9a, jms_timestamp=1404142195240, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@581bce9a, JMSXUserID=mqcls1 , JMS_IBM_PutApplType=28, JMS_IBM_MsgType=8, JMS_IBM_PutDate=20140630, jms_messageId=ID:414d5120414344534430513720202020537502dd20130f02, JMS_IBM_PutTime=15295524, JMSXDeliveryCount=1, jms_redelivered=false, priority=4, JMSXAppID=Websphere MQ Client for Java, id=f8aacfea-e655-e19d-1b7f-fd99389bf095, timestamp=1404139693356}]
2014-06-30 10:48:13,356 WARN [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] jms.ChannelPublishingJmsMessageListener$GatewayDelegate - failure occurred in gateway sendAndReceive
org.springframework.integration.transformer.MessageTransformationException: failed to transform message
at org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:44)
at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:68)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:114)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:154)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:44)
at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:75)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:250)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:224)
at org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate.sendAndReceiveMessage(ChannelPublishingJmsMessageListener.java:485)
at org.springframework.integration.jms.ChannelPublishingJmsMessageListener.onMessage(ChannelPublishingJmsMessageListener.java:330)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:537)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:497)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1102)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1094)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:991)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.springframework.integration.transformer.MapToObjectTransformer.transformPayload(MapToObjectTransformer.java:41)
at org.springframework.integration.transformer.AbstractPayloadTransformer.doTransform(AbstractPayloadTransformer.java:33)
at org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:33)
... 25 more
2014-06-30 10:48:13,387 WARN [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1] listener.DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
org.springframework.integration.transformer.MessageTransformationException: failed to transform message
at org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:44)
at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:68)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:114)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:154)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:44)
at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:75)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:250)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:224)
at org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate.sendAndReceiveMessage(ChannelPublishingJmsMessageListener.java:485)
at org.springframework.integration.jms.ChannelPublishingJmsMessageListener.onMessage(ChannelPublishingJmsMessageListener.java:330)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:537)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:497)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1102)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1094)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:991)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.springframework.integration.transformer.MapToObjectTransformer.transformPayload(MapToObjectTransformer.java:41)
at org.springframework.integration.transformer.AbstractPayloadTransformer.doTransform(AbstractPayloadTransformer.java:33)
at org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:33)
... 25 more
抱歉格式不好。
谁能告诉我我在这里做错了什么?