Claus Ibsen created CAMEL-27205:
-----------------------------------

             Summary: camel-spring-rabbitmq - maximumRetryAttempts doc wrong; 
DLQ needs routing key
                 Key: CAMEL-27205
                 URL: https://issues.apache.org/jira/browse/CAMEL-27205
             Project: Camel
          Issue Type: Bug
          Components: camel-spring-rabbitmq
            Reporter: Claus Ibsen


h3. 1. maximumRetryAttempts counts retries, not attempts
The endpoint option says: "How many times a Rabbitmq consumer will try the same 
message if Camel failed to process the message (The number of attempts includes 
the initial try)". The code passes the value to 
{{RetryInterceptorBuilder.maxRetries(...)}}, which counts the retries after the 
first try. Tested with a failing route:
* unset (5): 6 tries
* {{maximumRetryAttempts=3}}: 4 tries
* {{1}}: 2 tries, {{0}}: 1 try

The component-level option already says "retry". The endpoint description (and 
the generated docs/catalog) should say "How many times ... will retry ... (not 
counting the first try)", or the code should use {{maxRetries(n - 1)}} if 
"attempts" is the intended meaning (that changes behaviour).

h3. 2. deadLetterQueue fails to start without deadLetterRoutingKey
With {{autoDeclare=true}}, {{deadLetterExchange}} and {{deadLetterQueue}} but 
no {{deadLetterRoutingKey}}, the consumer fails to start:
{noformat}
java.lang.IllegalArgumentException: 'routingKey' must be non-null
{noformat}
This also happens with {{deadLetterExchangeType=fanout}}, where the routing key 
is not used at all.
{noformat}
spring-rabbitmq:orders?queues=orders&autoDeclare=true&deadLetterExchange=orders.dlx&deadLetterExchangeType=fanout&deadLetterQueue=orders.dlq
{noformat}

h3. Where
* 
{{components/camel-spring-parent/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQEndpoint.java}}:
 {{maximumRetryAttempts}} {{@UriParam}} description; {{declareElements}}: {{new 
Binding(deadLetterQueue, QUEUE, deadLetterExchange, deadLetterRoutingKey, 
...)}} with a null key.
* {{.../DefaultListenerContainerFactory.java}}: 
{{builder.maxRetries(endpoint.getMaximumRetryAttempts())}}.

h3. Suggested fix
* Correct the {{maximumRetryAttempts}} description.
* When {{deadLetterRoutingKey}} is null, bind the dead letter queue with {{""}} 
for {{fanout}} and {{headers}} exchanges; for {{direct}}/{{topic}} either use 
the consumer {{routingKey}} (RabbitMQ dead-letters with the original routing 
key when {{x-dead-letter-routing-key}} is not set) or fail with a clear message 
that names {{deadLetterRoutingKey}}.

Found while adding retry and dead letter options to the 
{{spring-rabbitmq-source}} Kamelet.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to