You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "ravjotbrar (via GitHub)" <gi...@apache.org> on 2025/01/03 20:30:06 UTC

[PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

ravjotbrar opened a new pull request, #16702:
URL: https://github.com/apache/camel/pull/16702

   # Description
   
   This PR implements a new parameter called enableManualAcks, which would make it possible for the user to enable manual acknowledgements in the client. By default, the parameter is set to false and messages will be automatically acknowledged. If set to true, the acknowledgement is added in the exchange's completion callback.
   
   # Target
   
   - [x ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build auto-formats your code. This will also be verified as part of the checks and your PR may be rejected if if there are uncommited changes after running `mvn clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16702:
URL: https://github.com/apache/camel/pull/16702#issuecomment-2569778419

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :robot: CI automation will test this PR automatically.
   
   :camel: Apache Camel Committers, please review the following items:
   
   * First-time contributors **require MANUAL approval** for the GitHub Actions to run
   
   * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot.
   
   * You can label PRs using `build-all`, `build-dependents`, `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
   
   * Build and test logs are available in the Summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. 
   
   * :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1903922804


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                @Override
+                public void onFailure(Exchange exchange) {
+                    LOG.error("Error: " + exchange.getExchangeId(), exchange.getException());

Review Comment:
   Also, please, use log markers instead of concatenating strings. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "ravjotbrar (via GitHub)" <gi...@apache.org>.
ravjotbrar commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1904485297


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Configuration.java:
##########
@@ -88,6 +88,8 @@ public class PahoMqtt5Configuration implements Cloneable {
     private int executorServiceTimeout = 1;
     @UriParam(defaultValue = "-1")
     private long sessionExpiryInterval = -1;
+    @UriParam(defaultValue = "false")
+    private boolean manualAcksEnabled = false;

Review Comment:
   Good point. Removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #16702:
URL: https://github.com/apache/camel/pull/16702


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1905540845


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                @Override
+                public void onFailure(Exchange exchange) {
+                    LOG.error("Error: " + exchange.getExchangeId(), exchange.getException());

Review Comment:
   I wasn't very clear in my review. I meant that I suggested you to do this:
   
   ```LOG.error("Rollback due to error processing Exchange ID: {}", exchange.getExchangeId(), exchange.getException());```
   
   I don't think you need actual SLF4J log markers here. Just the `{}` instead of concatenating strings.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "ravjotbrar (via GitHub)" <gi...@apache.org>.
ravjotbrar commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1904503731


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "ravjotbrar (via GitHub)" <gi...@apache.org>.
ravjotbrar commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1905894496


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                @Override
+                public void onFailure(Exchange exchange) {
+                    LOG.error("Error: " + exchange.getExchangeId(), exchange.getException());

Review Comment:
   Ah gotcha. Fixed. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "ravjotbrar (via GitHub)" <gi...@apache.org>.
ravjotbrar commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1904530137


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                @Override
+                public void onFailure(Exchange exchange) {
+                    LOG.error("Error: " + exchange.getExchangeId(), exchange.getException());

Review Comment:
   Thank you both for the review. Addressed!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "ravjotbrar (via GitHub)" <gi...@apache.org>.
ravjotbrar commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1904486023


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Configuration.java:
##########
@@ -548,6 +550,22 @@ public void setSessionExpiryInterval(long sessionExpiryInterval) {
         this.sessionExpiryInterval = sessionExpiryInterval;
     }
 
+    /**
+     * Sets whether to use manual acknowledgements for the client.
+     *
+     * By default, this is false and message will be automatically acknowledged. If set to true, the acknowledgement is
+     * added in the exchange's completion callback.
+     *
+     */
+    public boolean isManualAcksEnabled() {
+

Review Comment:
   Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-21589: Enable manual acks mqtt5 [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #16702:
URL: https://github.com/apache/camel/pull/16702#discussion_r1902913693


##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Configuration.java:
##########
@@ -88,6 +88,8 @@ public class PahoMqtt5Configuration implements Cloneable {
     private int executorServiceTimeout = 1;
     @UriParam(defaultValue = "-1")
     private long sessionExpiryInterval = -1;
+    @UriParam(defaultValue = "false")
+    private boolean manualAcksEnabled = false;

Review Comment:
   a boolean is false by default, so remove



##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+
+                @Override
+                public void onFailure(Exchange exchange) {
+                    LOG.error("Error: " + exchange.getExchangeId(), exchange.getException());

Review Comment:
   A better description, such as "Rollback message due to error processing ..."



##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Configuration.java:
##########
@@ -548,6 +550,22 @@ public void setSessionExpiryInterval(long sessionExpiryInterval) {
         this.sessionExpiryInterval = sessionExpiryInterval;
     }
 
+    /**
+     * Sets whether to use manual acknowledgements for the client.
+     *
+     * By default, this is false and message will be automatically acknowledged. If set to true, the acknowledgement is
+     * added in the exchange's completion callback.
+     *
+     */
+    public boolean isManualAcksEnabled() {
+

Review Comment:
   remove empty line



##########
components/camel-paho-mqtt5/src/main/java/org/apache/camel/component/paho/mqtt5/PahoMqtt5Consumer.java:
##########
@@ -155,6 +160,23 @@ public Exchange createExchange(MqttMessage mqttMessage, String topic) {
         paho.setHeader(PahoMqtt5Constants.CAMEL_PAHO_MSG_PROPERTIES, mqttMessage.getProperties());
 
         exchange.setIn(paho);
+        if (getEndpoint().getConfiguration().isManualAcksEnabled()) {
+            exchange.getExchangeExtension().addOnCompletion(new Synchronization() {
+                @Override
+                public void onComplete(Exchange exchange) {
+                    try {
+                        PahoMqtt5Consumer.this.client.messageArrivedComplete(mqttMessage.getId(), mqttMessage.getQos());
+                    } catch (MqttException e) {
+                        throw new RuntimeException(e);

Review Comment:
   dont rethrown but log a WARN about not able to commit



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org