Camel ActiveMQ如何在没有消费者

时间:2016-06-23 10:14:12

标签: apache-camel activemq jbossfuse

我的应用程序包含许多在JBoss Fuse 6.2.1中运行的OSGi包。每个捆绑包都有一个从ActiveMQ端点消耗的Camel路由。使用VirtualTopics交换数据。

ProducerBundle 发布到主题VirtualTopic.MyTopic

ConsumerBundle A 从队列Consumer.A.VirtualTopic.MyTopic消耗 ConsumerBundle B 从队列Consumer.B.VirtualTopic.MyTopic消耗 ConsumerBundle C 从队列Consumer.C.VirtualTopic.MyTopic消耗

在特定时刻,消费者C关闭,其捆绑包已卸载,永远不会再回来。然而,消息仍然排入Consumer.C.VirtualTopic.MyTopic队列 如何销毁此类队列?

当队列填满时,ActiveMQ会暂停生产者,并且我无法在消息上设置很短的时间,因为其他消费者可能需要一段时间才能处理每条消息。我无法修改VirtualTopic结构。我有完全访问权限 ActiveMQ配置和Camel路由。
还有其他方法可以处理这种情况吗?

<!-- producer route -->
<route id="ProducerRoute"/>
    <from uri="direct:trigger"/>
    <to uri="activemq:topic:VirtualTopic.MyTopic"/>
</route>

<!-- each consumer route -->
<route id="ConsumerARoute">
    <from uri="activemq:Consumer.A.VirtualTopic.MyTopic"/>
    <to uri="bean:myProcessor"/>
</route>

3 个答案:

答案 0 :(得分:1)

查看Apache ActiveMQ文档,了解如何删除非活动队列/主题,例如:here

答案 1 :(得分:0)

我选择了积极的解决方案:我挂钩OSGi包生命周期,当它停止时我使用JMX MBeanServer来销毁现在不需要的队列。

由于我的包使用蓝图进行管理,因此我选择了一个带有destroy方法的bean 这是一个示例实现:

我的豆子

package org.darugna.osgi;

import javax.management.MBeanServer;
import javax.management.ObjectName;

public class QueueDestroyer {

    private static final String[] QUEUES_TO_DESTROY = {
        "Consumer.A.VirtualTopic.MyTopic"
    };

    private MBeanServer mBeanServer;

    public void setMbeanServer(MBeanServer mBeanServer) {
        this.mBeanServer = mBeanServer;
    }

    public void destroy() throws Exception {
        ObjectName brokerName = new ObjectName("org.apache.activemq:type=Broker,brokerName=amq");
        for (String queueName : QUEUES_TO_DESTROY) {
            Object returnValue = mBeanServer.invoke(brokerName,
                    "removeQueue",
                    new Object[]{queueName},
                    new String[]{String.class.getName()});
        }
    }

}

Blueprint.xml

<blueprint>

    <reference id="mbeanServer" interface="javax.management.MBeanServer" 
               availability="mandatory"/>

    <bean id="queueDestroyer" class="org.darugna.osgi.QueueDestroyer" 
          destroy-method="destroy">
        <property name="mbeanServer" ref="mbeanServer"/>
    </bean>

    <camelContext>
        <route>
            <from uri="activemq:Consumer.A.VirtualTopic.MyTopic"/>
            <to uri="bean:myProcessor"/>
        </route>
    <camelContext>

</blueprint>    

答案 2 :(得分:-1)

我有类似的情况,但我无法使用Claus的建议,因为在我的经纪人中有其他队列没有消费者,我不想删除它们。 在我的情况下,我正在运行带有结构的JBoss Fuse 6.1.0(我认为与更新版本的Fuse相同):我刚刚删除了消费者(在我的情况下,我刚刚删除了消费者的配置文件),之后我使用hawtio控制台中的删除按钮删除了队列。