I need to consume the error message and depending on the cause of the failure either retry or discard the message. To test this I'm explicitly throwing a run time exception from my code.I see that the originalMessage and headers in the ErrorMessage are null. But i see my payload as a byte array and my custom header in the failedMessage of the payload .How can i retrieve this? i see no getters specified for the failedMessage property in the payload of ErrorMessage.
Asked
Active
Viewed 520 times
0
-
Are you sure that the data is correct and meaningful? it is in an ErrorMessage! – Amin Feb 04 '19 at 06:46
-
As far as ive read the ErrorMessage is supposed to have the originalMessage and the failedMessage as well as the headers. The originalMessage is supposed to have the data before any transformation has occurred. I just need to know how i can get the failedMessage (a generic message) from the payload. I see no exposed getters. – Ananya Antony Feb 04 '19 at 06:52
-
I guess you want to access a private field. see [this post](https://stackoverflow.com/questions/1196192/how-to-read-the-value-of-a-private-field-from-a-different-class-in-java) – Amin Feb 04 '19 at 07:03
-
What's wrong with `ErrorMessage.getOriginalMessage()`? – Oleg Zhurakousky Feb 04 '19 at 07:17
-
@OlegZhurakousky its coming as null. Same for ErrorMessage.getHeaders(). Is there a way i can get the failedMessage from the payload – Ananya Antony Feb 04 '19 at 07:28
-
I can't see how the framework could possibly produce the ErrorMessage with original message being null. Do you have an example somewhere on GitHub that reproduces this condition? – Oleg Zhurakousky Feb 04 '19 at 07:38
-
@OlegZhurakousky Sorry i havent got it on github. Im listening to a pattern of topics (destinationIsPattern=true). Once my message is consumed and send to the businessService i explicitly throw a runtimeexception from it to test the error handling. Im consuming the ErrorMessage as below `@ServiceActivator(inputChannel="errorChannel") public void error(ErrorMessage message) { LOGGER.info("Handling ERROR Payload: " + message.getOriginalMessage()); LOGGER.info("Handling Exception : "+message.getPayload().getCause()); }` – Ananya Antony Feb 04 '19 at 07:52
-
@OlegZhurakousky Also because my destinationIsPattern is true i cant enable dlq. So ive overridden the spring retry template and limited retries to 1. – Ananya Antony Feb 04 '19 at 08:27
-
Seems like you're doing a lot but only showing a small subset of it. Please consider posting a sample project that reproduces it on GitHub. – Oleg Zhurakousky Feb 04 '19 at 08:38
-
1Just cast the payload to `MessagingException` - see my answer. – Gary Russell Feb 04 '19 at 14:24
1 Answers
1
The failedMessage
is a property of the payload, which is a MessagingException
. Cast it...
Message<?> failed = ((MessagingException) em.getPayload()).getFailedMessage();

Gary Russell
- 166,535
- 14
- 146
- 179
-
Thanks! I already did that. Got it from on of your answers in a previous question. – Ananya Antony Feb 07 '19 at 12:43