简体   繁体   中英

How to use root cause Exception type in Exception Router in Spring Integration

I am trying to handle the exception in my code . However the Messaging Exception wraps my customized exception thrown by the code.

Now I want to use the Exception router , and if the type is my customized exception , then i would like to send the message to queue a , else queue b.

Now the issue is, router is receiving the messaging exception object , hence it is not able to identify my exception , and is sending the message to queue b, while exception root cause is still my customized exception.

Router is given below:

 <int:exception-type-router input-channel="exceptionRouterChannel" 
     default-output-channel="unpersistedDest">
    <int:mapping exception-type=
                    "org.springframework.integration.MessageRejectedException"
        channel="validationErrorsDest" />
    <int:mapping exception-type=
                        "com.error.StaleMessageException"
        channel="discardDest" />
</int:exception-type-router>       

Can anyone help on this.

Actually, there is no reason to map to messaging exceptions. ErrorMessageExceptionTypeRouter does the loop for cause.getCause() : https://github.com/spring-projects/spring-integration/blob/master/spring-integration-core/src/main/java/org/springframework/integration/router/ErrorMessageExceptionTypeRouter.java#L41 .

So, you can map only for your exceptions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM