Skip to content

Commit

Permalink
Branch-2.7 fix Delayed Messages (#11374)
Browse files Browse the repository at this point in the history
Cherry-picking #10762 broke the Delayed messages feature in branch-2.7.

This patch restores the method that has been dropped
  • Loading branch information
eolivelli committed Jul 20, 2021
1 parent 29bb338 commit f9475fe
Showing 1 changed file with 19 additions and 0 deletions.
Expand Up @@ -59,6 +59,7 @@
import org.apache.pulsar.broker.service.persistent.DispatchRateLimiter.Type;
import org.apache.pulsar.broker.transaction.buffer.exceptions.TransactionNotSealedException;
import org.apache.pulsar.client.impl.Backoff;
import org.apache.pulsar.common.api.proto.PulsarApi;
import org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.SubType;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.DispatchRate;
Expand Down Expand Up @@ -794,6 +795,24 @@ public void initializeDispatchRateLimiterIfNeeded(Optional<Policies> policies) {
}
}

@Override
public boolean trackDelayedDelivery(long ledgerId, long entryId, PulsarApi.MessageMetadata msgMetadata) {
if (!topic.isDelayedDeliveryEnabled()) {
// If broker has the feature disabled, always deliver messages immediately
return false;
}
synchronized (this) {
if (!delayedDeliveryTracker.isPresent()) {
// Initialize the tracker the first time we need to use it
delayedDeliveryTracker = Optional
.of(topic.getBrokerService().getDelayedDeliveryTrackerFactory().newTracker(this));
}

delayedDeliveryTracker.get().resetTickTime(topic.getDelayedDeliveryTickTimeMillis());
return delayedDeliveryTracker.get().addMessage(ledgerId, entryId, msgMetadata.getDeliverAtTime());
}
}

protected synchronized Set<PositionImpl> getMessagesToReplayNow(int maxMessagesToRead) {
if (!redeliveryMessages.isEmpty()) {
return redeliveryMessages.getMessagesToReplayNow(maxMessagesToRead);
Expand Down

0 comments on commit f9475fe

Please sign in to comment.