You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/03/13 17:18:08 UTC

[camel] branch main updated: deliveryTag -> For manual ack (#9471)

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 bfba7e62e08 deliveryTag -> For manual ack (#9471)
bfba7e62e08 is described below

commit bfba7e62e08973fb261d232ca406e16bdada9d2e
Author: mayurvaid-redvest <10...@users.noreply.github.com>
AuthorDate: Mon Mar 13 22:48:00 2023 +0530

    deliveryTag -> For manual ack (#9471)
    
    * deliveryTag -> For manual ack
    
    * Adding DELIVERY_TAG as constant
    
    * Referring DELIVERY_TAG constants
    
    * Adding readme docs for manual acknowledgement
    
    * Fixing checkstyle
---
 .../src/main/docs/spring-rabbitmq-component.adoc        | 17 +++++++++++++++++
 .../springrabbit/DefaultMessagePropertiesConverter.java |  3 +++
 .../component/springrabbit/SpringRabbitMQConstants.java |  1 +
 3 files changed, 21 insertions(+)

diff --git a/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc b/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc
index 40a88a0e29e..a1c8fd82d08 100644
--- a/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc
+++ b/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc
@@ -238,5 +238,22 @@ from("direct:order")
   .toD("spring-rabbit:order-${header.orderType}");
 ----
 
+== Manual Acknowledgement 
+
+If we need to manually acknowledge a message for some use case , we can 
+do it by setting and acknowledgeMode to Manual and using the below snippet
+of code to get Channel and deliveryTag to manually acknowledge the message
+
+[source,java]
+----
+from("spring-rabbitmq:%s?queues=%s&acknowledgeMode=MANUAL")
+    .process(exchange -> {
+        Channel channel = exchange.getProperty(SpringRabbitMQConstants.CHANNEL, Channel.class);
+        long deliveryTag = exchange.getIn().getHeader("deliveryTag",Long.class);
+         channel.basicAck(deliveryTag,false);
+    })
+
+----
+
 
 include::spring-boot:partial$starter.adoc[]
diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultMessagePropertiesConverter.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultMessagePropertiesConverter.java
index 3d0ce92174a..8f72aa5d912 100644
--- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultMessagePropertiesConverter.java
+++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultMessagePropertiesConverter.java
@@ -71,6 +71,9 @@ public class DefaultMessagePropertiesConverter implements MessagePropertiesConve
             if (messageProperties.getTimestamp() != null) {
                 answer.put(Exchange.MESSAGE_TIMESTAMP, messageProperties.getTimestamp().getTime());
             }
+
+            // Helps in getting to acknowledge manually
+            answer.put(SpringRabbitMQConstants.DELIVERY_TAG, messageProperties.getDeliveryTag());
         }
 
         return answer;
diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQConstants.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQConstants.java
index 7e51f6384e7..634aef08ece 100644
--- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQConstants.java
+++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/SpringRabbitMQConstants.java
@@ -39,6 +39,7 @@ public final class SpringRabbitMQConstants {
     public static final String DELIVERY_LIMIT = "x-delivery-limit";
     public static final String EXPIRES = "x-expires";
     public static final String SINGLE_ACTIVE_CONSUMER = "x-single-active-consumer";
+    public static final String DELIVERY_TAG = "deliveryTag";
 
     private SpringRabbitMQConstants() {
         // Constants class