Announcement Announcement Module
Collapse
No announcement yet.
Infinite loop when occurs exception. I use StatefulRetryOperationsInterceptor. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Infinite loop when occurs exception. I use StatefulRetryOperationsInterceptor.

    Hi folks.

    I need to retry until fixed number when unexpected errors occur. For that, I wrote my spring configuration as following.

    <bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.Si mpleMessageListenerContainer"
    p:connectionFactory-ref="consumerConnectionFactory"
    p:queueNames="${rabbit.queue.user.recommend},${rab bit.queue.user.recommend.follow}"
    p:concurrentConsumers="5"
    p:recoveryInterval="10000"
    p:messageListener-ref="messageListenerAdapter"
    p:errorHandler-ref="errorHandler"
    p:adviceChain-ref="retryInterceptor" />

    <bean id="retryTemplate" class="org.springframework.batch.retry.support.Ret ryTemplate">
    <property name="retryPolicy">
    <bean class="org.springframework.batch.retry.policy.Simp leRetryPolicy">
    <property name="maxAttempts" value="3" />
    </bean>
    </property>
    </bean>

    <bean id="retryInterceptor"
    class="org.springframework.batch.retry.interceptor .StatefulRetryOperationsInterceptor"
    p:retryOperations-ref="retryTemplate">
    </bean>
    I expected only three times are retried but infinite error occurs as following.
    Who can help me?

    2012-12-18 17:25:12 [ERROR](DefaultErrorHandler.java:13) Error on message listener.
    org.springframework.amqp.rabbit.listener.ListenerE xecutionFailedException: Failed to invoke target method 'handleMessage' with argument type = [class xxx.FollowUnfollowRecommend], value = [{FollowUnfollowRecommend[targetUser=...}]
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.invokeListenerMethod(Message ListenerAdapter.java:453)
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.onMessage(MessageListenerAda pter.java:344)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.doInvokeListener(AbstractM essageListenerContainer.java:505)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.invokeListener(AbstractMes sageListenerContainer.java:469)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.access$001(SimpleMessageList enerContainer.java:57)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer$1.invokeListener(SimpleMessa geListenerContainer.java:106)
    at sun.reflect.GeneratedMethodAccessor32.invoke(Unkno wn Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:183)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :150)
    at org.springframework.batch.retry.interceptor.Statef ulRetryOperationsInterceptor$MethodInvocationRetry Callback.doWithRetry(StatefulRetryOperationsInterc eptor.java:173)
    at org.springframework.batch.retry.support.RetryTempl ate.doExecute(RetryTemplate.java:240)
    at org.springframework.batch.retry.support.RetryTempl ate.execute(RetryTemplate.java:187)
    at org.springframework.batch.retry.interceptor.Statef ulRetryOperationsInterceptor.invoke(StatefulRetryO perationsInterceptor.java:145)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy16.invokeListener(Unknown Source)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.invokeListener(SimpleMessage ListenerContainer.java:587)
    at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.executeListener(AbstractMe ssageListenerContainer.java:451)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.doReceiveAndExecute(SimpleMe ssageListenerContainer.java:463)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.receiveAndExecute(SimpleMess ageListenerContainer.java:447)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.access$200(SimpleMessageList enerContainer.java:57)
    at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer$AsyncMessageProcessingConsum er.run(SimpleMessageListenerContainer.java:532)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.NoSuchMethodException:
    xxx.RecommendUserConsumerImpl.handleMessage(xxx.Fo llowUnfollowRecommend)
    at java.lang.Class.getMethod(Class.java:1605)
    at org.springframework.util.MethodInvoker.prepare(Met hodInvoker.java:178)
    at org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter.invokeListenerMethod(Message ListenerAdapter.java:436)
    ... 25 more

  • #2
    Hello!
    I expected only three times are retried
    What do you expect should heppens when all your attemps are exhausted?
    The reason of Retry is about to make some count of attempts and rethrow Exception if service doesn't apply the agruments in the end.
    In your case RetryTemplate made his work and rethrown Exception to the caller: SimpleMessageListenerContainer.
    Here happens a rollback and your Message is returning to RabbitMQ.
    But your Listener continues to work, so you get the Message from RabbitMQ and send it to the same service with the same RetryInteceptor.
    It happens infinitely.

    Well, what do you want to achieve after all your attemps? There is some feature in the RetryTemplate - RecoveryCallback.
    I recommend you to make a search on this forum and read docs: http://static.springsource.org/sprin...qp.html#d4e552
    Also take a look into StatefulRetryOperationsInterceptorFactoryBean and StatelessRetryOperationsInterceptorFactoryBean

    Cheers,
    Artem

    Comment

    Working...
    X