我想知道在ActiveMQ中是否有任何属性,用户可以限制ActiveMQ在达到一定阈值后不接受输入队列中的消息?到目前为止,我能够找到它的流量控制使用内存约束。我想在输入队列达到一定阈值时动态地阻塞我的输入队列。有没有其他的软件可以帮助我实现我的目标?
可能的方法是将自定义代理拦截器插入ActiveMQ。
修改Spring broker配置:
<plugins>
<bean id="myPlugin" class="org.foo.CheckThresholdPlugin"/>
</plugins>
然后扩展BrokerPlugin重写send方法。
package org.foo;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerPlugin;
public class CheckThresholdPlugin extends BrokerFilter {
public void send(ProducerBrokerExchange producer, Message message) throws Exception {
boolean isOverThreshold = /* figure it out by getting Destination from Message */
if (isOverThreshold) {
throw new Exception("The threshold is exceeded.");
} else {
super.send(producer, message);
}
}
}