ActiveMQ - 以编程方式删除队列
StackOverflowers 同胞,有没有办法以编程方式删除 ActiveMQ 中的队列或主题?我正在使用 ActiveMQ 的标准持久性,并且我的应用程序要求在启动时动态重新创建所有新队列(除非队列中存储有消息,在这种情况下,队列应保持存在)。
我还通过会话以编程方式创建所有队列。是否有与该过程等效的方法,仅删除队列?查询和迭代现有队列也很有用,但我还没有找到一种方法来做到这一点。
Fellow StackOverflowers, is there a way for me to remove a queue or a topic in ActiveMQ programmatically? I am using ActiveMQ's standard persistency, and my application requires that, on startup, all new queues be dynamically re-created (unless there are messages stored in the queue, in which case, the queue should remain to exist).
I am also creating all queues programmatically through sessions. Is there an equivalent to that procedure, only to delete a queue? Querying and iterating through the existing queues would also be useful, but i haven't found a way to do that yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然没有很多具体的例子,但这里有一些关于它的文档:
http://activemq.apache.org/how-do- i-purge-a-queue.html
While there's not a lot of concrete examples, there's some documentation about it here :
http://activemq.apache.org/how-do-i-purge-a-queue.html
您还可以删除在一段时间内不活动的目标。自 Active MQ 5.4 起可用
或者,如果您运行嵌入式 ActiveMQ,则可以使用 API 删除目标: Region.removeDestination< /a>
You can also Delete Destinations that are inactive for some period of time. Available since Active MQ 5.4
Alternatively if you are running ActiveMQ embedded you can use the API to remove destinations: Region.removeDestination
要以编程方式从 ActiveMQ 中删除目标,您需要通过 JMX 使用代理 MBean (
org.apache.activemq: BrokerName=localhost,Type=Broker
)。我在 Gist 上发布了一些示例代码来演示这一点,包括使用removeTopic
方法:http://gist.github.com/439668
希望有帮助。
布鲁斯
To remove a destination from ActiveMQ programmatically, you will need to do so via JMX using the
removeTopic
andremoveQueue
methods on the broker MBean (org.apache.activemq:BrokerName=localhost,Type=Broker
). I have posted some example code to demonstrate this, including the use of theremoveTopic
method, over on Gist:http://gist.github.com/439668
Hope that helps.
Bruce
如果你使用spring JmsTemplate,你可以这样做:
If you use spring JmsTemplate, you can do it this way: