JBoss 7.4 ActiveMQ Artemis 队列无法绑定到特定的 JNDI 名称

问题描述 投票:0回答:1

我正在从事从 EAP 6.4 到 7.4 的 JBoss 迁移。 发现的问题之一是将 HornetQ 替换为 ActiveMQ Artemis 版本 2.16.0.redhat-00022。我的具体问题是创建的队列的 JNDI 绑定。

在 HornetQ 上,使用以下代码创建队列:

import org.hornetq.api.jms.management.JMSServerControl;
...
...
JMSServerControl srv_c = getJMSServerControl(); // this method gets the object from MBServer
srv.createQueue("MyQName", "queue/MyQName", null, false);

在代码的其他部分,我可以通过 JNDI 名称搜索队列:

import javax.jms.Queue;
...
...
ctx = new InitialContext();
Queue ourQueue = (Queue) ctx.lookup("queue/MyQName");
if(ourQueue == null) {
  log.error("Queue not found!");
} else {
  log.info("Queue found");
}

在 Artemis 上寻找等效项时,我尝试使用 ActiveMQServerControl 并指定队列创建的配置。

import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
...
...
ActiveMQServerControl srv_c = getJMSServerControl(); // also found via MBServer
String queueConfig = "{" +
  "\"name\": \"MyQName\"," +
  "\"address\": \"jms.queue.MyQName\"," +
  "\"durable\": false," +
  "\"entries\": [\"java:/queue/MyQName\"]" +
  "}";
srv_c.createQueue(queueConfig);

但是,当我尝试通过 JNDI 查找队列时,它总是返回该对象不存在。在整个系统中,队列是通过 JNDI 检索的,这就是为什么我需要这样做。

java jndi activemq-artemis hornetq jboss-eap-7
1个回答
0
投票

您传递给

ActiveMQServerControl.createQueue
的 JSON 包含无效的“条目”。有关哪些属性有效的详细信息,请参阅 JavaDoc
QueueConfiguration

也就是说,您几乎肯定应该使用 WildFly 管理客户端 之一,而不是尝试直接使用 ActiveMQ Artemis 的嵌入式实例。通过使用 WildFly 管理,您将可以访问丰富的模型,包括所有必要的 JMS 相关操作(包括添加队列)。此外,这些更改将反映在模型中,这提供了自动更新磁盘上的 XML 配置文件(例如

standalone-full.xml
)等好处。

需要注意的是,在这种情况下,WildFly 本身管理 JNDI 条目,而不是 ActiveMQ Artemis。这就是为什么当您在 WildFly 中查找 JMS 管理对象时,您使用

org.wildfly.naming.client.WildFlyInitialContextFactory
而不是 ActiveMQ Artemis 中的类。

© www.soinside.com 2019 - 2024. All rights reserved.