我使用Spring和Jaxb来监听JMSQueue,然后将JMS消息解组为java对象。我希望在我的@JmsListener端点上获得该Java对象。但相反,我得到了一个TextMessage对象。使用调试器我可以逐步执行代码,看到转换到java对象的过程正在发生,但它永远不会成为我的终点。
这是我的配置:
@Bean
public DefaultJmsListenerContainerFactory myContainerFactory() {
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactoryProxy());
factory.setDestinationResolver(destinationResolver());
factory.setMessageConverter(messageConverter());
factory.setConcurrency("1-1");
return factory;
}
@Bean
public MessageConverter messageConverter(){
MarshallingMessageConverter converter = new MarshallingMessageConverter();
Jaxb2Marhsaller jaxbMarshaller = new Jaxb2Marhsaller ();
jaxbMarshaller.setPackagesToScan("mypackage.jms.model");
converter.setUnmarshaller(jaxbMarshaller);
converter.setMarshaller(jaxbMarshaller);
return converter;
}
And my endpoint:
@Component
public class QueueMessageReceiver {
@JmsListener(containerFactory = "myContainerFactory", destination = "jms/Queue")
public void process(Message message) {
try {
System.out.println(message);
}catch(Exception e){
e.printStackTrace();
}
}
}
问题是QueueMessageReceiver.process方法有TextMessage而不是转换后的对象。非常感谢帮助。
答案 0 :(得分:1)
尝试更改流程方法以使用您期望的对象而不是消息
@JmsListener(containerFactory = "myContainerFactory", destination = "jms/Queue")
public void process(YourAwesomeObject theObject) {
....
}