Fail Saga without rolling back transaction

34 views
Skip to first unread message

Pete Johnson

unread,
Aug 18, 2014, 8:15:47 AM8/18/14
to nginn-me...@googlegroups.com
I've got a saga where I handle a command and if some validation fails I call SetCompleted.
I want to populate the error_info column of the command but if I throw a PermanentMessageProcessingException then the transaction is rolledback. 
Is there a way to set the error info without rolling back the transaction?

Thanks

Rafal Gwizdala

unread,
Aug 18, 2014, 8:39:46 AM8/18/14
to nginn-me...@googlegroups.com
Hi Pete,

I think I don't yet understand what's the exact problem or what you're trying to achieve, so let's start with some questions/suggestions
1. Why do you SetCompleted when a validation fails? SetCompleted will complete the saga (but you can't throw exceptions then)
2. Throwing an exception from a message handler or a saga will always roll back the transaction. Then the exception information will be stored in error_info column in the failing message record, and message will be re-scheduled for a retry later. 
3. error_info column is meant for storing last error information if message processing ends with an error. It's filled automatically when an exception occurs, there's no api to set it manually from your code.
4. PermanentMessageProcessingException informs the message bus that there's no point in retrying the message because the error will not go away. It will mark message as failed (F) and won't attempt to process it again.
Please provide more info about your code if my explanations aren't relevant
Rafal


--
You received this message because you are subscribed to the Google Groups "nginn-messagebus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginn-messageb...@googlegroups.com.
To post to this group, send email to nginn-me...@googlegroups.com.
Visit this group at http://groups.google.com/group/nginn-messagebus.

Pete Johnson

unread,
Aug 18, 2014, 9:10:05 AM8/18/14
to nginn-me...@googlegroups.com
Thanks for the response. I'm sorry if I wasn't clear.

I have a message that has a file path in it and this is handled by the saga. I add another message to the bus (to be picked up by a different subscriber) then call SetCompleted so that the transaction and the saga complete. If the file doesn't exist then I populate an 'Errors' property on this new message.

The original message looks like it completed without any errors in the database - error_info is null and the subqueue is 'X'. I would like to indicate on the original message that an error occurred so that it is easier to track down failures (i.e. where the file path is invalid). When I use the PermanentMessageProcessingException I cannot add the other message to the messagebus for my other subscriber to pick up.

Is that any clearer? I realise it may not be possible to work this way, but it would make it easier for me to see where the message had problems.

Rafal Gwizdala

unread,
Aug 18, 2014, 11:27:56 AM8/18/14
to nginn-me...@googlegroups.com
Ok, I see the problem now
But I think you're trying to do something against the framework.
1. Nginn-messagebus is fully transactional, and the transaction includes not only the incoming message being handled, but also all outgoing messages sent from the handler. So if you throw an exception the whole unit will be rolled back and no messages will be sent - everything will return to the state it was before receiving the message.
2. Setting the 'Error' property on a message being handled will have no effect - messages in the database are not updated after being handled so your modifications will not make it into database.
3. I'd recommend storing the error information elsewhere, for example in a dedicated database table, not in the message queue. You can also store this information in the saga (just add a property for that purpose to the saga state - it will be persisted in saga JSON).
4. If I had to store the error information somewhere I'd write it to a log file together with the message ID. And if any additional processing logic would be required in such case I'd publish a separate message with error record, just for the purpose of handling this event somehow.
Hope this helps you find the solution
Best regards
Rafal


PJohnson

unread,
Aug 18, 2014, 11:38:47 AM8/18/14
to nginn-me...@googlegroups.com
That's great thanks


--
You received this message because you are subscribed to a topic in the Google Groups "nginn-messagebus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nginn-messagebus/AevjsHcNOZg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nginn-messageb...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages