I want to wrap the call to outbound gateway in my integration application using hystrix command similar to how it is available in Spring boot application.
<int-http:outbound-gateway id="outbound.gateway"
request-channel="get.request.channel" url="http://localhost:9090/profileapplication"
http-method="GET" charset='UTF-8' reply-channel="reply.channel"
>
</int-http:outbound-gateway>
I have my outbound gateway as above.
I need this for a scenario where the target application is frequently down/not responsive and we are looking for a way to provide a mock response during those scenarios and provide a chance for the target application to recover.
Basically, I want to use hystrix command and simulate a circuit breaker pattern over here.
I feel using a combination of ExpressionEvaluatingRequestHandlerAdvice and RequestHandlerCircuitBreakerAdvice might be helpful but I did not find any docs how to use them together for my scenario.
With Spring Boot it seems simpler, but with Integration I find it is not clear.
If anyone has implemented similar behaviour by adding custom behaviour to outbound gateway please let us know.
UPDATE:
As per Suggestion I did as below,
Added the @EnableCircuitBreaker annotation to my Spring boot application class.
@SpringBootApplication
@RestController
@ImportResource("classpath:/META-INF/spring/integration/hystrix-outbound-config.xml")
@EnableCircuitBreaker
public class HystrixIntegrationApplication {
.. }
Also, added @HystrixCommand annotation to my Gateway interface as below,
@MessagingGateway
public interface HystrixServiceGateway {
@Gateway(requestChannel = "get.request.channel", replyChannel = "reply.channel")
@HystrixCommand(fallbackMethod="getMockdata")
String getMessage(String name);
default String getMockData(String name) {
return "Mock Data:" + name;
}
}
I added the method in the interface itself as java 8 supports default methods in interface.
I even tried with static methods in interface as below.
@MessagingGateway
public interface HystrixServiceGateway {
@Gateway(requestChannel = "get.request.channel", replyChannel = "reply.channel")
@HystrixCommand(fallbackMethod="getMockdata")
String getMessage(String name);
static String getMockData(String name) {
return "Mock Data:" + name;
}
}
I used Spring Boot 1.5.12 and Spring cloud Edgware.SR3 versions. I also added the spring-cloud-starter-hystrix and spring-cloud-starter-eureka dependencies to my application pom.xml.
Not sure if the @hystrix annotation seems to resolve the issue.