Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.activemq.broker.region.policy.MessageEvictionStrategy;
import org.apache.activemq.broker.region.policy.OldestMessageEvictionStrategy;
import org.apache.activemq.command.*;
import org.apache.activemq.management.MessageFlowStats;
import org.apache.activemq.thread.Scheduler;
import org.apache.activemq.transaction.Synchronization;
import org.apache.activemq.transport.TransmitCallback;
Expand Down Expand Up @@ -166,7 +165,7 @@ public void add(MessageReference node) throws Exception {
if (maximumPendingMessages > 0 && maximumPendingMessages < max) {
max = maximumPendingMessages;
}
if (!matched.isEmpty() && matched.size() > max) {
if (messageEvictionStrategy.isExpiryScanEnabled() && !matched.isEmpty() && matched.size() > max) {
removeExpiredMessages();
}
// lets discard old messages as we are a slow consumer
Expand Down Expand Up @@ -530,6 +529,7 @@ public void setMaximumPendingMessages(int maximumPendingMessages) {
this.maximumPendingMessages = maximumPendingMessages;
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove blank space

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed all 3

public MessageEvictionStrategy getMessageEvictionStrategy() {
return messageEvictionStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ public interface MessageEvictionStrategy {
*/
int getEvictExpiredMessagesHighWatermark();

/**
* Returns whether the eager expired-message scan is enabled.
* <p>
* When {@code false}, the O(n) scan inside
* {@link org.apache.activemq.broker.region.TopicSubscription#add} is skipped entirely.
* Set to {@code false} when messages carry no TTL, or when the scan cost outweighs
* the benefit of eagerly evicting expired messages from slow-consumer buffers.
* <p>
* See {@link MessageEvictionStrategySupport} for the default implementation that returns {@code true}.
*
* @return {@code true} if the expiry scan is enabled (default), {@code false} if skipped
*/
boolean isExpiryScanEnabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public abstract class MessageEvictionStrategySupport implements MessageEvictionStrategy {

private int evictExpiredMessagesHighWatermark = 1000;
private boolean expiryScanEnabled = true;

public int getEvictExpiredMessagesHighWatermark() {
return evictExpiredMessagesHighWatermark;
Expand All @@ -35,6 +36,27 @@ public int getEvictExpiredMessagesHighWatermark() {
public void setEvictExpiredMessagesHighWatermark(int evictExpiredMessagesHighWaterMark) {
this.evictExpiredMessagesHighWatermark = evictExpiredMessagesHighWaterMark;
}



@Override
public boolean isExpiryScanEnabled() {
return expiryScanEnabled;
}

/**
* Controls whether the broker performs an eager expired-message scan when a
* non-durable topic subscription's pending slow-consumer buffer exceeds
* {@link #getEvictExpiredMessagesHighWatermark()}.
* <p>
* Set to {@code false} when messages carry no TTL, or when the O(n) scan cost
* outweighs the benefit of eagerly evicting expired messages from slow-consumer
* buffers. When messages have no TTL, every scan iterates the full buffer without
* removing anything, adding latency to every enqueue once the buffer exceeds the
* high-water mark.
*
* @param expiryScanEnabled {@code false} to skip the scan; {@code true} to enable it (default)
*/
public void setExpiryScanEnabled(boolean expiryScanEnabled) {
this.expiryScanEnabled = expiryScanEnabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class PolicyEntry extends DestinationMapEntry {

private MessageInterceptorStrategy messageInterceptorStrategy = null;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove blank space

public void configure(Broker broker,Queue queue) {
baseConfiguration(broker,queue);
if (dispatchPolicy != null) {
Expand Down Expand Up @@ -704,6 +705,7 @@ public void setEnableAudit(boolean enableAudit) {
this.enableAudit = enableAudit;
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove blank space

public int getMaxQueueAuditDepth() {
return maxQueueAuditDepth;
}
Expand Down
Loading