0

currently, I have Spring Integration Flow where reading payload from JMS queue, transforming to XML format, then send the XML payload to the core app. at the RecordSenderHandler, there is logic to make call rest API to my core app and store the response to Redis according to the response I received. If my core app is not accessible or something wrong with my backend, I flag as error HTTP 500. But I do want to retry the execution for certain times and limit maximum error I got. below is my code. any suggestions?

    @Bean
public IntegrationFlow jmsMessageDrivenFlowWithContainer() {
    return IntegrationFlows
            .from(Jms.messageDrivenChannelAdapter(
                    Jms.container(this.jmsConnectionFactory, recordDestinationQueue)
                            .concurrentConsumers(xmlConcurrentConsumers)
                            .maxConcurrentConsumers(xmlMaxConcurrentConsumers))
                    .errorChannel("errorChannel"))
           .handle(payloadSender(), e->e.advice(circuitBreakerAdvice()))
            .get();
}

@Bean
@ServiceActivator(inputChannel = "handleChannel")
public PayloadSender payloadSender() {
    return new PayloadSender ();
}

  @Bean
public RequestHandlerCircuitBreakerAdvice circuitBreakerAdvice() {
    RequestHandlerCircuitBreakerAdvice requestHandlerCircuitBreakerAdvice = new RequestHandlerCircuitBreakerAdvice();
    requestHandlerCircuitBreakerAdvice.setThreshold(3);
    requestHandlerCircuitBreakerAdvice.setHalfOpenAfter(15000);
    return requestHandlerCircuitBreakerAdvice;
}

1 Answers1

0

See Adding Behavior to Endpoints and in particular the RequestHandlerRetryAdvice.

.handle(..., e -> e.advice(retryAdvice()))

...

@Bean
public RequestHandlerRetryAdvice retryAdvice() {
    ...
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Hi Gary, could you give me sample to use circuit breaker. I tried with this line .handle(recordSenderHandler(), e->e.advice(circuitBreakerAdvice())) , but it doesn't work – kianaproudmoore Mar 31 '20 at 03:00
  • "Doesn't work" is never enough information. Also adding code is comments is not good here; it doesn't render well. Edit the question with your current configuration instead, and explain exactly what you mean by "doesn't work" (and add a comment indicating you have done so). Enabling a DEBUG logging is also a good way to debug things. – Gary Russell Mar 31 '20 at 03:23
  • please see my updated post for the code. I tried with RequestHandlerRetryAdvice with retryPolicy and BackOffPolicy worked fine. I could see retry counter displayed at the log. But when I tried with RequestHandlerCircuitBreakerAdvice, it's like nothing happen. in this case, I stop the service of the core app to get error connection refused – kianaproudmoore Mar 31 '20 at 03:35
  • thanks a lot. yeah, I get that. I'll raise the circuit breaker to separate question – kianaproudmoore Apr 01 '20 at 14:20