java - 如何在 ActiveMQ 中创建队列?

标签 java jms activemq

这是来自 ActiveMQ HelloWorld Example 的代码片段使用 ActiveMQ 创建队列

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");

   // Create a Connection
   Connection connection = connectionFactory.createConnection();
   connection.start();

   // Create a Session
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   // Create the destination (Topic or Queue)
   Destination destination = session.createQueue("TEST.FOO");

根据 ActiveMQ docs

This facility is provided for the rare cases where clients need to dynamically manipulate queue identity

看起来开发人员不应该使用 createQueue 创建队列。如果是,开发人员应该如何创建队列?他应该通过 ui 还是其他方式创建而不是通过编程来创建?

然后它进一步说

this method is not for creating the physical queue. The physical creation of queues is an administrative task and is not to be initiated by the JMS API.

我没明白上面的说法是什么意思?根据我的理解,开发人员应该手动创建队列。通过 web ui 或命令提示符。 createQueue 方法只会返回与手动创建的队列关联的对象吗?

最佳答案

在 ActiveMQ 中,您不必先创建目的地就可以使用它们。 ActiveMQ 代理根据需要创建与目标关联的物理资源,因此如果您在 JMS session 上调用 createQueue(),它会为您创建队列(如果它尚不存在)。

参见:http://activemq.apache.org/how-do-i-create-new-destinations.html

关于java - 如何在 ActiveMQ 中创建队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22048537/

相关文章:

java - 将AAR指向自身而不是Maven版本

java - 为什么我必须使用全新的行来单独打印变量?

jms - Apache Camel 多个 JMS 监听器

java - activemq jdbc 性能/延迟

java - 独立于语言的 JSP 自定义模式的 JSTL formatNumber

java - 创建唯一对象的列表

ActiveMQ - 如何为某些队列保留存储空间?

spring - ActiveMQ Failover transport + Spring JmsTemplate 常量重连

java - ActiveMQ:使用PooledConnectionFactory不会提高性能

jms - JCA JMS 和普通 JMS 有什么区别