From ea8c3cec36c228f1c460d0d907dc03789cfc3c24 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 7 Aug 2019 14:11:26 -0400 Subject: [PATCH] GH-259: Fix DLQ binding with custom routing key Fixes https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/259 Previously, a custom dead letter routing key would only be used in the binding if the dead letter queue itself also had a dead letter routing key. The wrong property was being tested for non-null while creating the binding. **cherry-pick to 2.2.x, 2.1.x** Resolves #260 Broken on 2.1.x by 75ebb08479de1fcfe514c557e35abfcac3acd5f6 --- .../provisioning/RabbitExchangeQueueProvisioner.java | 2 +- .../stream/binder/rabbit/RabbitBinderTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java index 279b70adc..5d5fad262 100644 --- a/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java +++ b/spring-cloud-stream-binder-rabbit-core/src/main/java/org/springframework/cloud/stream/binder/rabbit/provisioning/RabbitExchangeQueueProvisioner.java @@ -356,7 +356,7 @@ public class RabbitExchangeQueueProvisioner } Map arguments = new HashMap<>(properties.getDlqBindingArguments()); Binding dlqBinding = new Binding(dlq.getName(), DestinationType.QUEUE, - dlxName, properties.getDlqDeadLetterRoutingKey() == null ? routingKey + dlxName, properties.getDeadLetterRoutingKey() == null ? routingKey : properties.getDeadLetterRoutingKey(), arguments); declareBinding(dlqName, dlqBinding); 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 c30cbb88b..653dfdc87 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 @@ -547,6 +547,7 @@ public class RabbitBinderTests extends extProps.setDeadLetterExchangeType(ExchangeTypes.TOPIC); extProps.setDeadLetterRoutingKey("customDLRK"); extProps.setDlqDeadLetterExchange("propsUser3"); + // GH-259 - if the next line was commented, the test failed. extProps.setDlqDeadLetterRoutingKey("propsUser3"); extProps.setDlqExpires(60_000); extProps.setDlqLazy(true); @@ -577,6 +578,17 @@ public class RabbitBinderTests extends assertThat(bindings.get(0).getDestination()).isEqualTo("propsUser3.infra"); assertThat(bindings.get(0).getRoutingKey()).isEqualTo("foo"); + bindings = client.getBindingsBySource("/", "customDLX"); + n = 0; + while (n++ < 100 && bindings == null || bindings.size() < 1) { + Thread.sleep(100); + bindings = client.getBindingsBySource("/", "customDLX"); + } + assertThat(bindings.size()).isEqualTo(1); + assertThat(bindings.get(0).getSource()).isEqualTo("customDLX"); + assertThat(bindings.get(0).getDestination()).isEqualTo("customDLQ"); + assertThat(bindings.get(0).getRoutingKey()).isEqualTo("customDLRK"); + ExchangeInfo exchange = client.getExchange("/", "propsUser3"); n = 0; while (n++ < 100 && exchange == null) {