0

I am using Spring Retry. Earlier, I used @Retryable(value= Exception.class) & it worked correctly with retryAdvice(). The code correctly retried after getting any kind of exception. Recently, we have a requirement to not retry when MessageTimeoutException is encountered. In all other exceptions, we need to retry.

    @Override
    @Retryable(exclude = MessageTimeoutException.class)
    //@Retryable(exclude = org.springframework.integration.MessageTimeoutException.class)
    public byte[] sendMessage(byte[] message, String guid) {    
        responseBytes = tcpClientGateway.send(message);
        return responseBytes;
    }

    @Bean
    public RequestHandlerRetryAdvice retryAdvice() {
        RequestHandlerRetryAdvice retryAdvice = new RequestHandlerRetryAdvice();
        RetryTemplate retryTemplate = new RetryTemplate();
        FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
        fixedBackOffPolicy.setBackOffPeriod(50);
        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
        retryPolicy.setMaxAttempts(3);
        retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
        retryTemplate.setRetryPolicy(retryPolicy);
        retryAdvice.setRetryTemplate(retryTemplate);
        return retryAdvice;
    }

    @Bean
    @ServiceActivator(inputChannel = "emirOutboundChannel")
    public MessageHandler emirOutbound(AbstractClientConnectionFactory emirTcpCachedClientConnectionFactory) {
        TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
        List<Advice> list = new ArrayList<>();
        list.add(retryAdvice());
        tcpOutboundGateway.setAdviceChain(list);
        tcpOutboundGateway.setRemoteTimeout(16000);
        tcpOutboundGateway.setRequestTimeout(16000);
        tcpOutboundGateway.setSendTimeout(16000);
        tcpOutboundGateway.setConnectionFactory(emirTcpCachedClientConnectionFactory);
        return tcpOutboundGateway;
    }

Here's the exception that I wish to perform re-try upon. I am wondering what am I missing?

2023-08-16 21:47:54.635 my-project [Thread Id = 351182] ERROR org.springframework.integration.ip.tcp.TcpOutboundGateway:149 - Tcp Gateway exception
org.springframework.integration.MessageTimeoutException: Timed out waiting for response; component: EmirOutbound
    at org.springframework.integration.ip.tcp.TcpOutboundGateway.getReply(TcpOutboundGateway.java:293) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:234) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler.handleRequestMessage(AbstractReplyProducingMessageHandler.java:206) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at jdk.internal.reflect.GeneratedMethodAccessor153.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice$CallbackImpl.cloneAndExecute(AbstractRequestHandlerAdvice.java:166) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.advice.RequestHandlerRetryAdvice.lambda$doInvoke$1(RequestHandlerRetryAdvice.java:86) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:255) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.integration.handler.advice.RequestHandlerRetryAdvice.doInvoke(RequestHandlerRetryAdvice.java:86) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice.invoke(AbstractRequestHandlerAdvice.java:67) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.sun.proxy.$Proxy274.handleRequestMessage(Unknown Source) ~[?:?]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.doInvokeAdvisedRequestHandler(AbstractReplyProducingMessageHandler.java:153) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:137) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:56) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:317) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:272) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:233) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:47) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:46) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:38) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:96) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:86) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:513) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:486) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.sendOrSendAndReceive(GatewayProxyFactoryBean.java:661) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:586) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:553) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:542) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.sun.proxy.$Proxy240.send(Unknown Source) ~[?:?]
    at com.famulus.claimadj.dao.Emir.service.impl.EmirTcpMessageServiceImpl.sendMessage(EmirTcpMessageServiceImpl.java:32) ~[famulus-claimadj-dao-Emir-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.dao.Emir.service.impl.EmirTcpMessageServiceImpl$$FastClassBySpringCGLIB$$a2bdd82b.invoke(<generated>) ~[famulus-claimadj-dao-Emir-1.0.0.jar!/:1.0.0]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.retry.interceptor.RetryOperationsInterceptor$1.doWithRetry(RetryOperationsInterceptor.java:93) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke(RetryOperationsInterceptor.java:119) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:163) ~[spring-retry-1.3.1.jar!/:?]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.claimadj.dao.Emir.service.impl.EmirTcpMessageServiceImpl$$EnhancerBySpringCGLIB$$e3eb27ea.sendMessage(<generated>) ~[famulus-claimadj-dao-Emir-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.SendMessageToSocketServiceImpl.sendMessageToEmir(SendMessageToSocketServiceImpl.java:35) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.SendMessageToSocketServiceImpl$$FastClassBySpringCGLIB$$14e5b0a5.invoke(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.common.frameworks.logging.LoggingAspect.logAnnotateClass(LoggingAspect.java:44) ~[famulus-common-frameworks-1.0.0.jar!/:?]
    at jdk.internal.reflect.GeneratedMethodAccessor134.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.claimadj.logic.services.impl.SendMessageToSocketServiceImpl$$EnhancerBySpringCGLIB$$622bf3ca.sendMessageToEmir(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.ProcessB1ServiceImpl.processB1(ProcessB1ServiceImpl.java:227) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.ProcessB1ServiceImpl$$FastClassBySpringCGLIB$$2ffe53b4.invoke(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.common.frameworks.logging.LoggingAspect.logAnnotateClass(LoggingAspect.java:44) ~[famulus-common-frameworks-1.0.0.jar!/:?]
    at jdk.internal.reflect.GeneratedMethodAccessor134.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.claimadj.logic.services.impl.ProcessB1ServiceImpl$$EnhancerBySpringCGLIB$$9090be57.processB1(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.ClaimProcessingServiceImpl.processNcpdpRequest(ClaimProcessingServiceImpl.java:94) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.logic.services.impl.ClaimProcessingServiceImpl$$FastClassBySpringCGLIB$$c2ec1bc3.invoke(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.common.frameworks.logging.LoggingAspect.logAnnotateClass(LoggingAspect.java:44) ~[famulus-common-frameworks-1.0.0.jar!/:?]
    at jdk.internal.reflect.GeneratedMethodAccessor134.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) ~[spring-aop-5.3.8.jar!/:5.3.8]
    at com.famulus.claimadj.logic.services.impl.ClaimProcessingServiceImpl$$EnhancerBySpringCGLIB$$ae5417e4.processNcpdpRequest(<generated>) ~[famulus-claimadj-logic-1.0.0.jar!/:1.0.0]
    at com.famulus.claimadj.apis.setup.TcpServerEndpoint.processIncomingMessage(TcpServerEndpoint.java:23) ~[classes!/:1.0.0]
    at jdk.internal.reflect.GeneratedMethodAccessor154.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper$HandlerMethod.invoke(MessagingMethodInvokerHelper.java:1101) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:583) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:478) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:356) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:108) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:105) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:56) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:317) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:233) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:47) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:46) ~[spring-messaging-5.3.8.jar!/:5.3.8]
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:521) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:491) ~[spring-integration-core-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.ip.tcp.TcpInboundGateway.doOnMessage(TcpInboundGateway.java:123) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.ip.tcp.TcpInboundGateway.onMessage(TcpInboundGateway.java:101) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.ip.tcp.connection.TcpNioConnection.sendToChannel(TcpNioConnection.java:406) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at org.springframework.integration.ip.tcp.connection.TcpNioConnection.run(TcpNioConnection.java:270) ~[spring-integration-ip-5.5.1.jar!/:5.5.1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
    at java.lang.Thread.run(Thread.java:834) [?:?]
lavin249
  • 25
  • 6

2 Answers2

2

You need include. exclude means retry all exceptions except these.

In newer versions; these are deprecated and replaced with retryFor and noRetryFor respectively.

    /**
     * Exception types that are retryable. Defaults to empty (and, if exclude is also
     * empty, all exceptions are retried).
     * @return exception types to retry
     * @deprecated in favor of {@link #retryFor()}.
     */
    @AliasFor("retryFor")
    @Deprecated
    Class<? extends Throwable>[] include() default {};

    /**
     * Exception types that are retryable. Defaults to empty (and, if noRetryFor is also
     * empty, all exceptions are retried).
     * @return exception types to retry
     * @since 2.0
     */
    @AliasFor("include")
    Class<? extends Throwable>[] retryFor() default {};

    /**
     * Exception types that are not retryable. Defaults to empty (and if include is also
     * empty all exceptions are retried). If includes is empty but exclude is not, all
     * not excluded exceptions are retried
     * @return exception types not to retry
     * @deprecated in favor of {@link #noRetryFor()}.
     */
    @Deprecated
    @AliasFor("noRetryFor")
    Class<? extends Throwable>[] exclude() default {};

    /**
     * Exception types that are not retryable. Defaults to empty (and, if retryFor is also
     * empty, all exceptions are retried). If retryFor is empty but noRetryFor is not, all
     * other exceptions are retried
     * @return exception types not to retry
     * @since 2.0
     */
    @AliasFor("exclude")
    Class<? extends Throwable>[] noRetryFor() default {};
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I edited and corrected my question. I apologies for the all the inconvenience caused to you. I intended to mean that we do not have to retry on the exception. Thank you for providing the references. Also, I was able to figure out the issue and corrected the code. I have added my answer and it is working as expected. – lavin249 Aug 30 '23 at 04:05
1

I was able to figure out the issue. I used SimpleRetryPolicy

public SimpleRetryPolicy(int maxAttempts,
                         Map<Class<? extends Throwable>,Boolean> retryableExceptions,
                         boolean traverseCauses)

Keeping flag for traverseCauses as true leads to matching the exception until match is found.

HashMap has the exception which should not be retried and hence it's value i.e. the boolean flag is set to false. It simply states that MessageTimeoutException should not be retried.

    @Bean
    public RequestHandlerRetryAdvice retryAdvice() {
        RequestHandlerRetryAdvice retryAdvice = new RequestHandlerRetryAdvice();
        RetryTemplate retryTemplate = new RetryTemplate();
        FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
        fixedBackOffPolicy.setBackOffPeriod(50);
        Map<Class<? extends Throwable>, Boolean> mapExceptions = new HashMap<Class<? extends Throwable>, Boolean>();
        mapExceptions.put(MessageTimeoutException.class, false);
        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(3, mapExceptions, true);
        retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
        retryTemplate.setRetryPolicy(retryPolicy);
        retryAdvice.setRetryTemplate(retryTemplate);
        return retryAdvice;
    }
lavin249
  • 25
  • 6
  • So, your `@Retryable` has confused us. And I think you have to use `traverseCauses = true`, because in the end of handling that `MessageTimeoutException` is wrapped to other `MessageHandlingException`. I believe we have fixed that at some point since `TcpOutboundGateway` throws this `MessageTimeoutException` as a valid `MessageHandlingException` with all the information, therefore no need in wrapping. Consider to upgrade to the latest version: https://spring.io/projects/spring-integration#learn – Artem Bilan Aug 30 '23 at 14:07