Hi,
I would like to contribute a very simple patch file to
org.apache.camel.component.rabbitmq.RabbitMQDeclareSupport
I am interested in the following configuration to actually perform the
binding while skipping the declarations (or demanding they exist passively).
- declare = true
- skipQueueDeclare = true
- skipExchangeDeclare = true
- skipQueueBind = false
I am not entirely sure this micro-patch requires testing or documentation
changes.
Also, this is my first contribution/patch. If there are any remarks or
guidelines that I am missing, please let me know so I can improve it.
I am carrying out the change on branch main (dc66701db86).
Addendum:
I would like to know if this change could possibly be backported to older
versions, eg: v3.11.x.
diff --git
components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
index d69c554d04c..1ad4bb11a36 100644
---
components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQDeclareSupport.java
+++
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,18 @@ 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 {
+
+ //if (!endpoint.isPassive()) { log.warn("Forcing passive because
declaration was skipped"); }
+ channel.exchangeDeclarePassive(exchange);
+ channel.queueDeclarePassive(queue);
+ channel.queueBind(queue, exchange, emptyIfNull(routingKey),
bindingArgs);
+ }
+
private String emptyIfNull(final String routingKey) {
return routingKey == null ? "" : routingKey;
}