java - ActiveMQ - 从 JMS 远程主机接收时无法识别对象

标签 java jms activemq instanceof activemq-artemis

我正在两台 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/

相关文章:

java - 将 Keycloak 与 pgbouncer 一起使用

java - 允许最终程序员扩展 API 枚举

java - JButton 子类在单击/透明错误之前不显示按钮

java - 发送 JMS 消息的单元测试代码

java - 无法将消息发送到 weblogic 队列

java - ViewPostIme 指针 1/0

java - 如何使用 java 和 spring 3.0 同时处理来自 JMS 主题(不是队列)的多条消息?

c# - 在不删除的情况下读取 ActiveMQ 消息

java - 您会使用发布/订阅或队列来进行长时间运行的后台进程吗?

ubuntu - Apache ActiveMQ 5.11.1 无法在 Ubuntu 中启动