I'm working on a message based service that queues all incoming requests and handles them later. What is the best practice for handling errors. For example malformed messages or communication errors when sending the information to the next system.
By using transactions it is possible to cope with the latter, however when a message is malformed there is no use to retry it nor keep it. Is there any idea to implement different error handling for different scenarios and if it is, how should it be done?
Thanks!
I think you're on the right track. There's three general patterns here:
Normal processing applies.
Perhaps some resource you need to process the message is unavailable. In this case, set the transaction to rollbackOnly and the message will be redelivered. Hopefully your JMS implementation supports the notion of delayed redelivery so that you're not reprocessing the same message thousands of times until your MIA resource becomes available again. If not (yeah, I'm looking at you, WebSphere MQ), what I usually do is push the message into another JMS queue reserved for temporarily unprocessable messages and commit. When the MIA resource comes back on line, I procedurally read all the messages off that queue and write them back to the main [original] queue where they're processed to completion.
Suppress the exception and commit the transaction. You'll never see that message again. To keep an audit trail of invalid messages:
The main point, though, is to make sure you commit the transaction if you know you will never be able to process that message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With