From 5278837b07477efe9fddcd1f2dfa39789aa7b3b5 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 5 Oct 2016 14:27:44 -0400 Subject: [PATCH] CSt-GH-670 Change default requeueRejected to false Fixes spring-cloud/spring-cloud-stream#670 --- .../src/main/asciidoc/overview.adoc | 16 +++++++++++----- .../binder/rabbit/RabbitConsumerProperties.java | 2 +- .../stream/binder/rabbit/RabbitBinderTests.java | 8 +------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spring-cloud-stream-binder-rabbit-docs/src/main/asciidoc/overview.adoc b/spring-cloud-stream-binder-rabbit-docs/src/main/asciidoc/overview.adoc index fb9d5d7f1..f2ecdd825 100644 --- a/spring-cloud-stream-binder-rabbit-docs/src/main/asciidoc/overview.adoc +++ b/spring-cloud-stream-binder-rabbit-docs/src/main/asciidoc/overview.adoc @@ -41,9 +41,13 @@ For partitioned producers/consumers the queues are suffixed with the partition i Using the `autoBindDlq` option, you can optionally configure the binder to create and configure dead-letter queues (DLQs) (and a dead-letter exchange `DLX`). The dead letter queue has the name of the destination, appended with `.dlq`. If retry is enabled (`maxAttempts > 1`) failed messages will be delivered to the DLQ. -If retry is disabled (`maxAttempts = 1`), you should set `requeueRejected` to false so the failed message will be routed to the DLQ, instead of being requeued. +If retry is disabled (`maxAttempts = 1`), you should set `requeueRejected` to `false` (default) so that a failed message will be routed to the DLQ, instead of being requeued. In addition, `republishToDlq` causes the binder to publish a failed message to the DLQ (instead of rejecting it); this enables additional information to be added to the message in headers, such as the stack trace in the `x-exception-stacktrace` header. -This option does not need retry enabled or the `requeueRejected` property set to `true`. +This option does not need retry enabled; you can republish a failed message after just one attempt. + +IMPORTANT: Setting `requeueRejected` to `true` will cause the message to be requeued and redelivered continually, which is likely not what you want unless the failure issue is transient. +In general, it's better to enable retry within the binder by setting `maxAttempts` to greater than one, or set `republishToDlq` to `true`. + See <> for more information about these properties. The framework does not provide any standard mechanism to consume dead-letter messages (or to re-route them back to the primary queue). @@ -116,9 +120,9 @@ recoveryInterval:: + Default: `5000`. requeueRejected:: - Whether delivery failures should be requeued. + Whether delivery failures should be requeued when retry is disabled or republishToDlq is false. + -Default: `true`. +Default: `false`. requestHeaderPatterns:: The request headers to be transported. + @@ -130,7 +134,9 @@ Default: `[STANDARD_REPLY_HEADERS,'*']`. republishToDlq:: By default, messages which fail after retries are exhausted are rejected. If a dead-letter queue (DLQ) is configured, RabbitMQ will route the failed message (unchanged) to the DLQ. -If set to `true`, the bus will republish failed messages to the DLQ with additional headers, including the exception message and stack trace from the cause of the final failure. +If set to `true`, the binder will republish failed messages to the DLQ with additional headers, including the exception message and stack trace from the cause of the final failure. ++ +Default: false transacted:: Whether to use transacted channels. + diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitConsumerProperties.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitConsumerProperties.java index 7e24b4a58..53f9885eb 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitConsumerProperties.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitConsumerProperties.java @@ -46,7 +46,7 @@ public class RabbitConsumerProperties { private boolean republishToDlq; - private boolean requeueRejected = true; + private boolean requeueRejected = false; private String[] replyHeaderPatterns = new String[] {"STANDARD_REPLY_HEADERS", "*"}; diff --git a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java index 680d54067..58f97aca8 100644 --- a/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java +++ b/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/RabbitBinderTests.java @@ -137,6 +137,7 @@ public class RabbitBinderTests extends public void testConsumerProperties() throws Exception { RabbitTestBinder binder = getBinder(); ExtendedConsumerProperties properties = createConsumerProperties(); + properties.getExtension().setRequeueRejected(true); properties.getExtension().setTransacted(true); Binding consumerBinding = binder.bindConsumer("props.0", null, createBindableChannel("input", new BindingProperties()), properties); @@ -170,7 +171,6 @@ public class RabbitBinderTests extends properties.getExtension().setPrefix("foo."); properties.getExtension().setPrefetch(20); properties.getExtension().setRequestHeaderPatterns(new String[] { "foo" }); - properties.getExtension().setRequeueRejected(false); properties.getExtension().setTxSize(10); properties.setInstanceIndex(0); consumerBinding = binder.bindConsumer("props.0", "test", createBindableChannel("input", new BindingProperties()), @@ -242,7 +242,6 @@ public class RabbitBinderTests extends consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.getExtension().setDurableSubscription(true); consumerProperties.setMaxAttempts(1); // disable retry - consumerProperties.getExtension().setRequeueRejected(false); DirectChannel moduleInputChannel = createBindableChannel("input", createConsumerBindingProperties(consumerProperties)); moduleInputChannel.setBeanName("durableTest"); moduleInputChannel.subscribe(new MessageHandler() { @@ -284,7 +283,6 @@ public class RabbitBinderTests extends consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.getExtension().setDurableSubscription(false); consumerProperties.setMaxAttempts(1); // disable retry - consumerProperties.getExtension().setRequeueRejected(false); BindingProperties bindingProperties = createConsumerBindingProperties(consumerProperties); DirectChannel moduleInputChannel = createBindableChannel("input", bindingProperties); moduleInputChannel.setBeanName("nondurabletest"); @@ -310,7 +308,6 @@ public class RabbitBinderTests extends consumerProperties.getExtension().setPrefix(TEST_PREFIX); consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.setMaxAttempts(1); // disable retry - consumerProperties.getExtension().setRequeueRejected(false); consumerProperties.getExtension().setDurableSubscription(true); BindingProperties bindingProperties = createConsumerBindingProperties(consumerProperties); DirectChannel moduleInputChannel = createBindableChannel("input", bindingProperties); @@ -357,7 +354,6 @@ public class RabbitBinderTests extends properties.getExtension().setPrefix("bindertest."); properties.getExtension().setAutoBindDlq(true); properties.setMaxAttempts(1); // disable retry - properties.getExtension().setRequeueRejected(false); properties.setPartitioned(true); properties.setInstanceIndex(0); DirectChannel input0 = createBindableChannel("input", createConsumerBindingProperties(properties)); @@ -545,7 +541,6 @@ public class RabbitBinderTests extends consumerProperties.getExtension().setPrefix("bindertest."); consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.setMaxAttempts(1); // disable retry - consumerProperties.getExtension().setRequeueRejected(false); consumerProperties.setPartitioned(true); consumerProperties.setInstanceIndex(0); DirectChannel input0 = createBindableChannel("input", createConsumerBindingProperties(consumerProperties)); @@ -633,7 +628,6 @@ public class RabbitBinderTests extends consumerProperties.getExtension().setAutoBindDlq(true); consumerProperties.getExtension().setRepublishToDlq(true); consumerProperties.setMaxAttempts(1); // disable retry - consumerProperties.getExtension().setRequeueRejected(false); consumerProperties.getExtension().setDurableSubscription(true); DirectChannel moduleInputChannel = createBindableChannel("input", createConsumerBindingProperties(consumerProperties)); moduleInputChannel.setBeanName("dlqPubTest");