【发布时间】:2016-12-15 09:00:25
【问题描述】:
这是我的用例:
-
RESTFul 调用服务以使用 jmsTemplate 在 jms 队列中创建消息:
@Autowired JmsTemplate jmsTemplate; public void sendMessage(final ApplicationContext appContext) { jmsTemplate.send(new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { ObjectMessage objectMessage = session.createObjectMessage(appContext); return objectMessage; } }); } -
另一个 RESTFul 调用服务从队列中获取消息,使用:
public ApplicationContext getMessage(final ApplicationContext appContext) { Object wObj = jmsTemplate.receive(MessagingConfiguration.NAMED_QUEUE); return (ApplicationContext)wObj; }
如您所见,它非常简单。我知道我可以使用带有 @JmsListener 注释的异步侦听器,但我需要同步接收操作。当我尝试这段代码时,我得到了一个类转换异常(这很有意义)。我的问题:如何将消息 (ActiveMQObjectMessage) 转换为我的 POJO (ApplicationContext)?
堆栈跟踪:
严重:servlet [dispatcher] 在路径 [/ApplicationContextManager] 的上下文中的 Servlet.service() 引发异常 [请求处理失败;嵌套异常是 java.lang.ClassCastException: org.apache.activemq.command.ActiveMQObjectMessage cannot be cast to com.tigidou.commons.appcontext.model.ApplicationContext] 根本原因 java.lang.ClassCastException: org.apache.activemq.command.ActiveMQObjectMessage 无法转换为 com.tigidou.commons.appcontext.model.ApplicationContext
【问题讨论】:
标签: java spring-boot activemq