mirror of https://github.com/apache/activemq.git
added the ability to discard old messages for non-durable topics if a maximum number of pending messages is reached
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@382421 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f1e4459644
commit
0d5de13537
|
@ -42,6 +42,7 @@ public class TopicSubscription extends AbstractSubscription {
|
|||
final protected UsageManager usageManager;
|
||||
protected int dispatched=0;
|
||||
protected int delivered=0;
|
||||
private int maximumPendingMessages = 0;
|
||||
|
||||
public TopicSubscription(Broker broker,ConnectionContext context, ConsumerInfo info, UsageManager usageManager) throws InvalidSelectorException {
|
||||
super(broker,context, info);
|
||||
|
@ -50,11 +51,20 @@ public class TopicSubscription extends AbstractSubscription {
|
|||
|
||||
public void add(MessageReference node) throws InterruptedException, IOException {
|
||||
node.incrementReferenceCount();
|
||||
if( !isFull() && !isSlaveBroker() ) {
|
||||
if( !isFull() && !isSlaveBroker()) {
|
||||
// TODO - if we have already dispatched too many messages to this slow consumer
|
||||
// should we avoid dispatching and just discard old messages as shown below
|
||||
dispatch(node);
|
||||
} else {
|
||||
synchronized(matched){
|
||||
matched.addLast(node);
|
||||
synchronized (matched) {
|
||||
matched.addLast(node);
|
||||
if (maximumPendingMessages > 0) {
|
||||
// lets discard old messages as we are a slow consumer
|
||||
while (matched.size() > maximumPendingMessages) {
|
||||
MessageReference oldMessage = (MessageReference) matched.removeFirst();
|
||||
oldMessage.decrementReferenceCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +132,18 @@ public class TopicSubscription extends AbstractSubscription {
|
|||
return delivered;
|
||||
}
|
||||
|
||||
public int getMaximumPendingMessages() {
|
||||
return maximumPendingMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of pending messages that can be matched against this consumer
|
||||
* before old messages are discarded.
|
||||
*/
|
||||
public void setMaximumPendingMessages(int maximumPendingMessages) {
|
||||
this.maximumPendingMessages = maximumPendingMessages;
|
||||
}
|
||||
|
||||
private boolean isFull() {
|
||||
return dispatched-delivered >= info.getPrefetchSize();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue