如何防止ActiveMQ优先队列上的低优先级消息饿死?

| 我正在一个需要实现优先队列的系统上工作。我们的消息具有不同的优先级,我们需要根据优先级处理消息。目前,出于多种原因,我们正在寻求将ActiveMQ用作我们的排队技术,其中之一就是支持优先级队列。 在ActiveMQ中使用优先级队列,解决饥饿的最佳方法是什么?具体来说,即使较高优先级的消息继续充斥队列,我们​​也需要确保即使是低优先级的消息也会最终得到处理。 ActiveMQ是否有内置的东西?还是我们需要构建我们自己的东西来随着消息的老化而增加优先级?     
已邀请:
        一种基本的方法是在消息变旧时提高优先级 这样一小时前发出的低优先级消息比新的高优先级消息具有更高的优先级
public class Message implements Comparable<Message>{

    private final long time;//timestamp from creation (can be altered to insertion in queue) in millis the lower this value the older the message (and more important that it needs to be handled)
    private final int pr;//priority the higher the value the higher the priority

    /**
     * the offset that the priority brings currently set for 3 hours 
     *
     * meaning a message with pr==1 has equal priority than a message with pr==0 from 3 hours ago
     */
    private static final long SHIFT=3*60*60*1000; 

    public Message(int priority){
        this.pr=priority;
        this.time = System.currentTimeMillis();
    }

    //I\'m assuming here the priority sorting is done with natural ordering
    public boolean compareTo(Message other){
        long th = this.time-this.pr*SHIFT;
        long ot = other.time-other.pr*SHIFT;
        if(th<ot)return 1;
        if(th>ot)return -1;
        return 0;
    }

}
如评论中所述,但是几个小时前来自低prio消息的洪水将暂时使新的高prio消息饿死,而正确地将这些消息间隔开将需要一种更复杂的方法 另一种方法是使用多个队列,每个队列一个,然后从低优先级队列中取出几个,从高优先级队列中取出。 后一种方法仅对低优先级确实可行,而我提供的第一种方法可以处理任意数量的优先级     

要回复问题请先登录注册