我使用BlockingQueue的现有代码创建了一个BlockingQueue列表(如私有List>队列;),我可以在其中处理消息.但是由于持久性问题,我们计划转向activemq.如果我们可以获得activemq队列列表(在java程序中不是来自配置文件),任何人都可以帮助我.我知道我可以在会话中使用createQueue来创建队列的单个实例,但我想要像BlockingQueue那样完成队列列表.
任何帮助将非常感激.
您可以从连接中使用DestinationSource获取可用队列的列表.
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection();
DestinationSource ds = connection.getDestinationSource();
Set<ActiveMQQueue> queues = ds.getQueues();
Run Code Online (Sandbox Code Playgroud)
编辑:创建队列看看ActiveMQ Hello world示例链接代码的作用是创建与jvm中嵌入的activeMQ-broker的连接
// Create a ConnectionFactory
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");
Run Code Online (Sandbox Code Playgroud)
上面的代码可能不明显的是该行:
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
Run Code Online (Sandbox Code Playgroud)
不仅会建立与代理的连接,还会在连接中嵌入代理(如果没有代理).在本页底部解释
该功能可以使用(您需要一个代理,但如果您想以其他方式设置它):
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?create=false");
Run Code Online (Sandbox Code Playgroud)
我非常喜欢ActiveMQ,但它提供的不仅仅是持久性,所以在做简单的事情时,事情似乎有点过于复杂.但希望不会吓到你.
| 归档时间: |
|
| 查看次数: |
5024 次 |
| 最近记录: |