On Fallback EIP
If you are using onFallback then that is intended to be local processing only where you can do a message transformation or call a bean or something as the fallback.
If you need to call an external service over the network then you should use onFallbackViaNetwork that runs in another independent HystrixCommand that uses its own thread pool to not exhaust the first command.
Options
The On Fallback EIP supports 1 options which are listed below:
Name | Description | Default | Type |
---|---|---|---|
fallbackViaNetwork |
Whether the fallback goes over the network. If the fallback will go over the network it is another possible point of failure and so it also needs to be wrapped by a HystrixCommand. It is important to execute the fallback command on a separate thread-pool, otherwise if the main command were to become latent and fill the thread-pool this would prevent the fallback from running if the two commands share the same pool. |
false |
Boolean |
Hystrix has many options as listed in Hystrix Configuration. For example to set a higher timeout to 5 seconds, and also let the circuit breaker wait 10 seconds before attempting a request again when the state was tripped to be open.
from("direct:start")
.circuitBreaker()
.hystrixConfiguration()
.executionTimeoutInMilliseconds(5000)
.circuitBreakerSleepWindowInMilliseconds(10000)
.end() // end Hystrix configuration
.to("http://fooservice.com/slow")
.onFallback()
.transform().constant("Fallback message")
.end()
.to("mock:result");
And in XML DSL:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<circuitBreaker>
<hystrixConfiguration executionTimeoutInMilliseconds="5000"
circuitBreakerSleepWindowInMilliseconds="10000"/>
<to uri="http://fooservice.com/slow"/>
<onFallback>
<transform>
<constant>Fallback message</constant>
</transform>
</onFallback>
</circuitBreaker>
<to uri="mock:result"/>
</route>
</camelContext>
You can also configure Hystrix globally and then refer to that configuration:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- a shared config which you can refer to from all your Hystrix EIPs -->
<hystrixConfiguration id="sharedConfig"
executionTimeoutInMilliseconds="5000"
circuitBreakerSleepWindowInMilliseconds="10000"/>
<route>
<from uri="direct:start"/>
<circuitBreaker configurationRef="sharedConfig">
<to uri="http://fooservice.com/slow"/>
<onFallback>
<transform>
<constant>Fallback message</constant>
</transform>
</onFallback>
</hystrix>
<to uri="mock:result"/>
</route>
</camelContext>