这是来自 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");
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/