我正在两台 JBoss 服务器上设置 JMS 请求回复。 在客户端中,我使用camel-jms和Fuse路由来创建调用。
.setExchangePattern(ExchangePattern.InOut)
.to(camelContext.getEndpoint(JMS_BEANID, JmsQueueEndpoint.class))
基本上它会创建临时队列并发送到服务器。
在服务器中,我创建 MessageListener
的实现来监听消息。
从调试 View message.getJMSReplyTo()
返回 ActiveMQTemporaryQueue
的实例。但是,当我尝试检查 message.getJMSReplyTo() instanceof ActiveMQTemporaryQueue
时,它返回 false
。我尝试自己创建 ActiveMQTemporaryQueue
检查按预期返回 true
,例如:
public void onMessage(Message message) {
Destination replyTo = message.getJMSReplyTo();
if (replyTo instanceof ActiveMQTemporaryQueue) {
// false, although the debugger show it is ActiveMQTemporaryQueue object
}
Destination test = new ActiveMQTemporaryQueue("localhost", "testQueue", (ActiveMQSession)session);
if (test instanceof ActiveMQTemporaryQueue) {
// true
}
}
客户端和服务器位于两个不同的Maven项目中(两个不同的war,部署到不同的服务器,相同的工作空间)。
我不知道发生了什么。您有什么建议吗?
最佳答案
我的猜测是,这是某种类加载问题,但根据您提供的信息很难判断。
也就是说,我强烈建议您不要在代码中使用任何实现对象(即ActiveMQTemporaryQueue
)。如果您想做的只是请求/回复,那么绝对不需要使用任何实现对象。如果您需要知道 getJMSReplyTo() 返回的值是否是临时队列,那么您可以简单地使用replyTo instanceof javax.jms.TemporaryQueue。如果您这样做,我认为您的问题将会得到解决。
关于java - ActiveMQ - 从 JMS 远程主机接收时无法识别对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59481309/