This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 11e94b7efb4 CAMEL-17892: perform binding even when declarations were
skipped (#7320)
11e94b7efb4 is described below
commit 11e94b7efb4667dd454370aec4e6b2951d6100f1
Author: Santiago Acosta <[email protected]>
AuthorDate: Mon Apr 4 06:07:40 2022 +0100
CAMEL-17892: perform binding even when declarations were skipped (#7320)
* CAMEL-17892: perform binding even when declarations were skipped
* CAMEL-17892: fix an integration test
* CAMEL-17892: fix broken checkstyle
Co-authored-by: Santiago Acosta <[email protected]>
---
.../camel/component/rabbitmq/RabbitMQDeclareSupport.java | 16 ++++++++++++++++
.../rabbitmq/integration/RabbitMQProducerIT.java | 2 +-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git
a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
index d69c554d04c..8b7b56158b0 100644
---
a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
+++
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
@@ -57,6 +57,11 @@ public class RabbitMQDeclareSupport {
// declare
declareAndBindQueue(channel, endpoint.getQueue(),
endpoint.getExchangeName(), endpoint.getRoutingKey(),
resolvedQueueArguments(), endpoint.getBindingArgs());
+ } else if (shouldBindQueue()) {
+ // we skipped declarations because they should exist, but we still
+ // want to bind both. Forced passive declaration
+ passivelyDeclareExchangeAndQueueAndBindThem(channel,
endpoint.getQueue(), endpoint.getExchangeName(),
+ endpoint.getRoutingKey(), endpoint.getBindingArgs());
}
}
@@ -150,6 +155,17 @@ public class RabbitMQDeclareSupport {
}
}
+ private void passivelyDeclareExchangeAndQueueAndBindThem(
+ final Channel channel, final String queue, final String exchange,
final String routingKey,
+ final Map<String, Object> bindingArgs)
+
+ throws IOException {
+
+ channel.exchangeDeclarePassive(exchange);
+ channel.queueDeclarePassive(queue);
+ channel.queueBind(queue, exchange, emptyIfNull(routingKey),
bindingArgs);
+ }
+
private String emptyIfNull(final String routingKey) {
return routingKey == null ? "" : routingKey;
}
diff --git
a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/integration/RabbitMQProducerIT.java
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/integration/RabbitMQProducerIT.java
index a44d38a8e3b..02bd32014b7 100644
---
a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/integration/RabbitMQProducerIT.java
+++
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/integration/RabbitMQProducerIT.java
@@ -89,7 +89,7 @@ public class RabbitMQProducerIT extends AbstractRabbitMQIT {
private String getBasicURI(String route) {
ConnectionProperties connectionProperties =
service.connectionProperties();
- return
String.format("rabbitmq:%s:%d/%s?routingKey=%s&username=%s&password=%s&skipQueueDeclare=true",
+ return
String.format("rabbitmq:%s:%d/%s?routingKey=%s&username=%s&password=%s&skipQueueDeclare=true&skipQueueBind=true",
connectionProperties.hostname(), connectionProperties.port(),
EXCHANGE, route, connectionProperties.username(),
connectionProperties.password());
}