Skip to content

Commit

Permalink
Process maxRedeliverCount is 0 of DeadLeddterPolicy (apache#14706)
Browse files Browse the repository at this point in the history
Signed-off-by: xiaolongran <[email protected]>


Fixes apache#14704 



### Motivation

When the user uses the function of DeadLetterPolicy, it is better than misoperation. MaxRedeliverCount may be set to 0. When it is set to 0, according to the current processing logic of the Java Client, the message will be pushed to the DeadLetter Topic every time.


### Modifications

- When MaxRedeliverCount <= 0 in DeadLetterPolicy, we reset MaxRedeliverCount to default value
  • Loading branch information
wolfstudy authored Mar 18, 2022
1 parent c4e4ddd commit 601fbdd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ public ConsumerBuilder<T> deadLetterPolicy(DeadLetterPolicy deadLetterPolicy) {
if (conf.getAckTimeoutMillis() == 0) {
conf.setAckTimeoutMillis(DEFAULT_ACK_TIMEOUT_MILLIS_FOR_DEAD_LETTER);
}

checkArgument(deadLetterPolicy.getMaxRedeliverCount() > 0, "MaxRedeliverCount must be > 0.");
conf.setDeadLetterPolicy(deadLetterPolicy);
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.pulsar.client.api.BatchReceivePolicy;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.DeadLetterPolicy;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.SubscriptionInitialPosition;
Expand Down Expand Up @@ -289,6 +290,15 @@ public void testConsumerBuilderImplWhenBatchReceivePolicyIsNotValid() {
.build());
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void testRedeliverCountOfDeadLetterPolicy() {
consumerBuilderImpl.deadLetterPolicy(DeadLetterPolicy.builder()
.maxRedeliverCount(0)
.deadLetterTopic("test-dead-letter-topic")
.retryLetterTopic("test-retry-letter-topic")
.build());
}

@Test
public void testConsumerBuilderImplWhenNumericPropertiesAreValid() {
consumerBuilderImpl.negativeAckRedeliveryDelay(1, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,12 @@ public void consumerBuilderTest() throws IOException {
consumerHandler.clearQueryParams();
consumerHandler.putQueryParam("receiverQueueSize", "1001");
consumerHandler.putQueryParam("deadLetterTopic", "dead-letter-topic");
consumerHandler.putQueryParam("maxRedeliverCount", "3");

conf = consumerHandler.getConf();
// receive queue size is the minimum value of default value (1000) and user defined value(1001)
assertEquals(conf.getReceiverQueueSize(), 1000);
assertEquals(conf.getDeadLetterPolicy().getDeadLetterTopic(), "dead-letter-topic");
assertEquals(conf.getDeadLetterPolicy().getMaxRedeliverCount(), 0);
assertEquals(conf.getDeadLetterPolicy().getMaxRedeliverCount(), 3);
}
}

0 comments on commit 601fbdd

Please sign in to comment.