当我使用 Spring 和 MQ 队列发送 OBject 消息时,为什么会收到 JMSBytesMessage
因此,我使用 Spring 和 IBM MQ Queue 发送一个对象:
public void sendObjectMessage(final Object message) {
// jmsTemplate.convertAndSend(message);
jmsTemplate.send(new MessageCreator()
{
public Message createMessage(Session session) throws JMSException
{
ObjectMessage outMessage = session.createObjectMessage((Serializable) message);
return(outMessage);
}
});
}
在调试过程中,我可以看到我确实将其作为对象消息发送。但是使用 Spring 的监听器实现,我在 onMessage() 方法中获取消息作为 JMSBytesMessages???
public void onMessage(Message message) {
System.out.println(">>>>>>> Recieved in onMessage");
System.out.println(message.getClass());
}
输出:
>>>>>>> Recieved in onMessage
class com.ibm.jms.JMSBytesMessage
有人知道这里发生了什么吗?这很难调试,因为它似乎发生在队列上???
感谢您的帮助
P.S 我也尝试使用以下命令捕获消息
if (message instanceof ObjectMessage) {
object = ((ObjectMessage) message).getObject();
}
,但
if (message instanceof JMSBytesMessage) {
System.out.println("ITS A BYTES MESSAGE!!!!!!!!!!!");
}
两者都不起作用???
So I'm sending an object using Spring and IBM MQ Queue:
public void sendObjectMessage(final Object message) {
// jmsTemplate.convertAndSend(message);
jmsTemplate.send(new MessageCreator()
{
public Message createMessage(Session session) throws JMSException
{
ObjectMessage outMessage = session.createObjectMessage((Serializable) message);
return(outMessage);
}
});
}
And during debugging I can see that I am indeed sending it as an object message. But using Spring's listener implementation I am picking up the messages in the onMessage() method as JMSBytesMessages????
public void onMessage(Message message) {
System.out.println(">>>>>>> Recieved in onMessage");
System.out.println(message.getClass());
}
OUTPUT:
>>>>>>> Recieved in onMessage
class com.ibm.jms.JMSBytesMessage
Anybody know whats going on here? This is difficult to debug as it seems to be happening on the queue???
Thanks for your help
P.S I've also tried to catch the message using
if (message instanceof ObjectMessage) {
object = ((ObjectMessage) message).getObject();
}
and
if (message instanceof JMSBytesMessage) {
System.out.println("ITS A BYTES MESSAGE!!!!!!!!!!!");
}
Neither of which work???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的第一个猜测是,您正在使用WebSphere AppServer,并且您的JMS队列对象(在JNDI中)被配置为本机MQ系列客户端,即您创建一个JMSObjectMessage,将其移交给会话,然后MQSeries认为它必须转换为 BytesMessage。
My first guess is, that you're using WebSphere AppServer and your JMS queue object (in JNDI) is configured to be a native MQ series client, i.e. you create a JMSObjectMessage which you hand over to the session and then MQSeries thinks it has to convert to BytesMessage.
我也有同样的问题。就我而言,我使用了错误的传输类型:
相反,它应该是:
I had the same problem. In my case, I was using the wrong transport type:
Instead it should have been: