创建activemq队列列表 [英] create list of activemq queue

查看:516
本文介绍了创建activemq队列列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现有的使用BlockingQueue的代码创建一个BlockingQueue列表(如私有List>队列;),在其中可以处理消息。
但是由于持久性问题,我们计划转移到activemq。
如果我们可以获取activemq队列列表(在Java程序中不是从配置文件中获取),谁能帮助我。我知道我可以在会话上使用createQueue来创建队列的单个实例,但是我希望像BlockingQueue那样完成队列列表。



任何帮助将不胜感激。

解决方案

要创建队列列表,您必须创建该列表,然后从会话对象中分别创建每个队列。 / p>

队列q = session.createQueue( someQueueName)



但是,这实际上并不能真正创建队列,因为队列是ActiveMQ进程/服务器中的持久性事物。这只会创建对给定标识符/名称的ActiveMQ队列的引用。



我不确定为什么现在需要十个队列。通常,每种事件类型或用例(或类似情况)有一个队列,然后使用并发使用者并行处理。



但是,当然,您总是可以做一些事情简单的for循环类似,一次创建一个队列并将它们附加到arraylist。请注意,您不能在其中仅包含 Event 对象的类型安全队列。



您可以通过事件发送 ObjectMessage s。只需创建一个:

  Event event = createEvent(..); //鉴于事件是可序列化的(需要能够将其持久化)。 
消息m = session.createObjectMessage(event);
//在ActiveMQ中照常发送消息。

从BlockingQueues转换为$ b时可能需要重新考虑代码中的一件事或几件事持久性ActiveMQ队列。


my existing code which uses BlockingQueue creates a list of BlockingQueue (like private List> queues;) in which I can put messages to process. However due to persistence issue we plan to shift to activemq. Can anyone please help me if we can get a list of activemq queue (in java program not from configuration file). I know that I can use createQueue on session to create a single instance of the queue but I want list of queue like done for BlockingQueue.

Any help would be much appreciated.

解决方案

To create a list of queues, you have to create that list, then create each queue individually from the session object.

Queue q = session.createQueue("someQueueName")

This, however, does not really "create" a queue in that sense, since a queue is a persistent "thing" in the ActiveMQ process/server. This will only create a reference to an ActiveMQ queue given an identifier/name.

I'm not sure why you need ten queues right up. Typically, you have one queue per event type or use case (or similar), then use concurrent consumers to process in parallel.

But of course, you can always do somethings similar by a simple for loop, creating one queue at a time and attaching them to an arraylist. Note that you cannot get type safe queues with only Event objects in them.

You can send ObjectMessages with events though. Just create one:

Event event = createEvent(..); // Given "Event" is serializable (need to be able to persist it).
Message m = session.createObjectMessage(event);
// Send message as usual in ActiveMQ.

It might be that you need to rethink one or a few things in your code when converting from BlockingQueues to persistent ActiveMQ queues.

这篇关于创建activemq队列列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆