concept Hystrix command in category camel

This is an excerpt from Manning's book Camel in Action.
You may have noticed in listing 7.14 the
COUNTER
instance, which is used as a global state stored outside the Hystrix command, and the fact that the example is constructed to fail every fifth call. How do you deal with exceptions thrown from therun
method?
Figure 7.8 The Hystrix command uses a thread from the regular thread pool ❶ to route the Camel message. The task runs, and upon completion, the command completes successfully ❷. But the task can also fail because of a time-out or an exception thrown during Camel routing, which causes the Hystrix command to run the fallback using a thread from the fallback thread pool ❸. This ensures isolation between run and fallback, adhering to the bulkhead principle.
![]()
Support for Hystrix on Spring Boot requires you to implement an
@Service
class, which holds the code to run as a Hystrix command. The following listing shows what you did to add fault-tolerance at number ❶ in figure 7.9.Here you create a new class,
ShoppingCartService
, which is responsible for calling the downstream shopping cart service. The class has been annotated with@Service
❶ (or@Component
), which is required by Spring when using Hystrix. The@HystrixCommand
annotation ❷ is added on the method that will be wrapped as a Hystrix command. All the code that runs inside this method will be under the control of Hystrix. Inside this method, you call the downstream service ❸ using Spring’sRestTemplate
to perform a REST call. Having a response, you transform this into a comma-separated string using Java 8 stream magic ❹. The@HystrixCommand
annotation specifies the name of the fallback method that refers to theemptyCart
method ❺. This method does what the name says: returns an empty shopping cart as its response.