You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/04/20 13:00:44 UTC

[GitHub] [camel] orpiske opened a new pull request, #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

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

   <!-- Uncomment and fill this section if your PR is not trivial
   - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
   - [ ] Each commit in the pull request should have 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.
   - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [ ] Run `mvn clean install -Psourcecheck` in your module with source check enabled to make sure basic checks pass and there are no checkstyle violations. A more thorough check will be performed on your pull request automatically.
   Below are the contribution guidelines:
   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


[GitHub] [camel] orpiske commented on a diff in pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
orpiske commented on code in PR #7474:
URL: https://github.com/apache/camel/pull/7474#discussion_r854162206


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   Thanks for the suggestion, I'll do it like that. 
   
   > Sadly the `end` is a "pain" part of Java DSL. When we make a source code generated Java DSL then we should make sure that we don't have this problem
   
   Yeah, it can be a bit confusing sometimes, but hopefully we'll get a change to adjust this. 
   



-- 
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


[GitHub] [camel] github-actions[bot] commented on pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7474:
URL: https://github.com/apache/camel/pull/7474#issuecomment-1103970531

   :x: Finished component verification: **1 component(s) test failed** out of 1 component(s) tested


-- 
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


[GitHub] [camel] davsclaus commented on a diff in pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
davsclaus commented on code in PR #7474:
URL: https://github.com/apache/camel/pull/7474#discussion_r854159261


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   Sadly the `end` is a "pain" part of Java DSL. When we make a source code generated Java DSL then we should make sure that we don't have this problem



-- 
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


[GitHub] [camel] github-actions[bot] commented on pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7474:
URL: https://github.com/apache/camel/pull/7474#issuecomment-1104063824

   :x: Finished component verification: **1 component(s) test failed** out of 2 component(s) tested


-- 
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


[GitHub] [camel] davsclaus commented on a diff in pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
davsclaus commented on code in PR #7474:
URL: https://github.com/apache/camel/pull/7474#discussion_r854135465


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   I think you should add 4 spaces in front of to so you can see its under the CB, and then add .end() to end the CB
   
   ```
   .circuitBreaker
       .to
   .end
   ```



-- 
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


[GitHub] [camel] github-actions[bot] commented on pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7474:
URL: https://github.com/apache/camel/pull/7474#issuecomment-1103905159

   :warning: This PR changes Camel components and will be tested automatically.


-- 
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


[GitHub] [camel] github-actions[bot] commented on pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #7474:
URL: https://github.com/apache/camel/pull/7474#issuecomment-1105084163

   :heavy_check_mark: Finished component verification: 0 component(s) test failed out of **1 component(s) tested**


-- 
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


[GitHub] [camel] orpiske commented on a diff in pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
orpiske commented on code in PR #7474:
URL: https://github.com/apache/camel/pull/7474#discussion_r854146162


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   Thanks @davsclaus. With regards to `end()` the CB, do you mean something like this?
   
   ```
   .circuitBreaker()
           .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
           .to(to);
   ```
   
   I tried a different interpretation of your suggestion (below), but the DSL doesn't seem very happy with it because the `Resilience4jConfigurationDefinition` doesn't resolve the `to`.  
   
   ```
   .circuitBreaker()
           .resilience4jConfiguration().circuitBreaker("pausableCircuit")
           .to(to)
   .end();
   ```
   
   Any suggestions?



-- 
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


[GitHub] [camel] orpiske merged pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
orpiske merged PR #7474:
URL: https://github.com/apache/camel/pull/7474


-- 
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


[GitHub] [camel] davsclaus commented on a diff in pull request #7474: CAMEL-17051: added a test and documentation for pausable along with circuit breaker EIP

Posted by GitBox <gi...@apache.org>.
davsclaus commented on code in PR #7474:
URL: https://github.com/apache/camel/pull/7474#discussion_r854158489


##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   Ah yeah you need to end the configuration too, so as the 1st one, but add a 2nd end to signal the end of the CB, as you can continue routing after the CB that does not participate inside the CB.
   
   circuit breaker
      to a
   end
   to b
   
   here A is under CB and B is not



##########
core/camel-core-engine/src/main/docs/modules/eips/pages/resume-strategies.adoc:
##########
@@ -219,3 +219,47 @@ from(from)
     .process(exchange -> LOG.info("Received an exchange: {}", exchange.getMessage().getBody()))
     .to(destination);
 ----
+
+You can also integrate the pausable API and the consumer listener with the circuit breaker EIP. For instance, it's
+possible to configure the circuit breaker so that it can manipulate the state of the listener based on success or on
+error conditions on the circuit.
+
+One example, would be to create a event watcher that checks for a downstream system availability. It watches for error events and, when they happen, it triggers a scheduled check. On success, it shuts down the scheduled check.
+
+An example implementation of this approach would be similar to this:
+
+[source,java]
+----
+CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("pausable");
+
+circuitBreaker.getEventPublisher()
+    .onSuccess(event -> {
+        LOG.info("Downstream call succeeded");
+        if (executorService != null) {
+            executorService.shutdownNow();
+            executorService = null;
+        }
+    })
+    .onError(event -> {
+        LOG.info(
+                "Downstream call error. Starting a thread to simulate checking for the downstream availability");
+
+        if (executorService == null) {
+            executorService = Executors.newSingleThreadScheduledExecutor();
+            // In a real world scenario, instead of incrementing, it could be pinging a remote system or
+            // running a similar check to determine whether it's available. That
+            executorService.scheduleAtFixedRate(() -> someCheckMethod(), 1, 1, TimeUnit.SECONDS);
+        }
+    });
+
+// Binds the configuration to the registry
+ getCamelContext().getRegistry().bind("pausableCircuit", circuitBreaker);
+
+from(from)
+    .pausable(new KafkaConsumerListener(), o -> canContinue())
+    .routeId("pausable-it")
+    .process(exchange -> LOG.info("Got record from Kafka: {}", exchange.getMessage().getBody()))
+    .circuitBreaker()
+        .resilience4jConfiguration().circuitBreaker("pausableCircuit").end()
+    .to(to);

Review Comment:
   Ah yeah you need to end the configuration too, so as the 1st one, but add a 2nd end to signal the end of the CB, as you can continue routing after the CB that does not participate inside the CB.
   
   ```
   circuit breaker
      to a
   end
   to b
   ```
   here A is under CB and B is not



-- 
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