Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 8: MicroProfile Fault Tolerance #17

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

ttelang
Copy link
Contributor

@ttelang ttelang commented Dec 9, 2024

Adding content for chapter08

Chapter 8: MicroProfile Fault Tolerance
Added chapter Introduction
@ttelang ttelang marked this pull request as draft December 9, 2024 17:34
Copy link

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on the tutorial! I read through it and noted a few minor corrections.

chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
chatper08/chapter08.adoc Outdated Show resolved Hide resolved
updating source code for Fallback example
changes to Timeout example source code
updating code for PaymentService with the fallback example
updating code examples for asynchronous and bulkhead sections
| `@CircuitBreaker` | Defines a circuit breaker mechanism to prevent repeated calls to a failing method. Includes parameters like `failureRatio`, `delay`, and `requestVolumeThreshold`.
| `@Fallback` | Specifies alternative logic to execute when the primary method fails. This ensures meaningful responses and graceful degradation.
| `@Bulkhead` | Limits the number of concurrent method executions to isolate system resources and prevent cascading failures.
|===
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add Asynchronous annotation

}
----

In this example, the `@Timeout(1000)` annotation specifies that the `processPayment` method must complete within 1000 milliseconds (1 second). If the execution exceeds this time, a `TimeoutException` will be thrown, and the process will terminate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to use @Timeout with @Asynchronous.

}
----

This example demonstrates the use of MicroProfile Fault Tolerance annotations `@Timeout` and `@Fallback` to enhance the resilience of a ProductService. The `@Timeout` annotation ensures that the `getProducts()` method, which fetches product data from a database, completes within a specified duration (2 seconds in this case). If the method exceeds this time or an exception occurs, the `@Fallback` annotation directs the application to invoke the `getProductsFromCache()` method, which retrieves data from a cache. This approach ensures consistent service availability and a seamless user experience, even during database delays or failures​.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also explain the calling sequence. Please add this blog somewhere in this chapter to demonstrate the usage of Asynchronous and also some invocation sequence was explained:
https://openliberty.io/blog/2020/06/04/asynchronous-programming-microprofile-fault-tolerance.html
https://openliberty.io/blog/2020/06/05/asynchronous-programming-microprofile-fault-tolerance-part-2.html


=== Using `@Asynchronous` Annotation

The *`@Asynchronous`* annotation in MicroProfile Fault Tolerance is used to enable asynchronous execution of methods. It allows operations to run in a separate thread, freeing up the main thread for other tasks. This approach enhances the application's responsiveness and scalability, particularly in high-concurrency or latency-sensitive scenarios.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be used when you specify @Timeout.

Copy link
Member

@Emily-Jiang Emily-Jiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chapter did not mention the configuration update here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants