Automatonymous ".Catch" method ignores sagarepository exceptions

308 views
Skip to first unread message

Roman Prykhodko

unread,
Oct 26, 2018, 2:20:24 AM10/26/18
to masstransit-discuss
Hi.
How can I catch exceptions of sagarepository during saving saga? If saga's transaction is reverting I want to do some activities, but .Catch method seems not to be good for that...

Roman Prykhodko

unread,
Oct 26, 2018, 2:40:34 AM10/26/18
to masstransit-discuss
I mean those repository exceptions, which are NOT caused by bubbling exceptions from logic. For example, this exception of Postgress:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Npgsql.PostgresException: 40001: could not serialize access due to read/write dependencies among transactions

Chris Patterson

unread,
Oct 28, 2018, 4:58:44 PM10/28/18
to masstrans...@googlegroups.com
If the saga repository encounters an exception during save, it will fault, and the message will be reprocessed. I'd recommend using the in-memory outbox to avoid publishing events if this occurs.

endpoint.UseInMemoryOutbox();

There isn't a way to capture the error of the saga repository.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/0ab72dfb-c59a-4233-9510-7ddb0e15aba5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roman Prykhodko

unread,
Oct 29, 2018, 1:35:33 AM10/29/18
to masstransit-discuss
UseInMemoryOutbox is great with events, but what if we have  .Then( saving some notsaga entity to DB )? If repository encounters an exception during save, saved entity is not deleted. Please advise. Thanks!


On Sunday, October 28, 2018 at 11:58:44 PM UTC+3, Chris Patterson wrote:
If the saga repository encounters an exception during save, it will fault, and the message will be reprocessed. I'd recommend using the in-memory outbox to avoid publishing events if this occurs.

endpoint.UseInMemoryOutbox();

There isn't a way to capture the error of the saga repository.


On Fri, Oct 26, 2018 at 1:40 AM Roman Prykhodko <prykhod...@gmail.com> wrote:
I mean those repository exceptions, which are NOT caused by bubbling exceptions from logic. For example, this exception of Postgress:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Npgsql.PostgresException: 40001: could not serialize access due to read/write dependencies among transactions


On Friday, October 26, 2018 at 9:20:24 AM UTC+3, Roman Prykhodko wrote:
Hi.
How can I catch exceptions of sagarepository during saving saga? If saga's transaction is reverting I want to do some activities, but .Catch method seems not to be good for that...

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Chris Patterson

unread,
Oct 29, 2018, 9:12:49 AM10/29/18
to masstrans...@googlegroups.com
The answer, quite simply, is don't do that.

You shouldn't be saving things to a database as part of a saga event handler. If anything, you should be producing an event (or sending a command) so that a separate consumer can perform the database write independent of the saga.

Interacting with a database within a saga is typically a bad practice, as the saga is already a combination of event-based processing and persistent state. And it's also why the Outbox is used, to avoid sending duplicate commands/events to those consumers which would perform the writes.



On Mon, Oct 29, 2018 at 12:35 AM Roman Prykhodko <prykhod...@gmail.com> wrote:
UseInMemoryOutbox is great with events, but what if we have  .Then( saving some notsaga entity to DB )? If repository encounters an exception during save, saved entity is not deleted. Please advise. Thanks!

On Sunday, October 28, 2018 at 11:58:44 PM UTC+3, Chris Patterson wrote:
If the saga repository encounters an exception during save, it will fault, and the message will be reprocessed. I'd recommend using the in-memory outbox to avoid publishing events if this occurs.

endpoint.UseInMemoryOutbox();

There isn't a way to capture the error of the saga repository.


On Fri, Oct 26, 2018 at 1:40 AM Roman Prykhodko <prykhod...@gmail.com> wrote:
I mean those repository exceptions, which are NOT caused by bubbling exceptions from logic. For example, this exception of Postgress:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Npgsql.PostgresException: 40001: could not serialize access due to read/write dependencies among transactions


On Friday, October 26, 2018 at 9:20:24 AM UTC+3, Roman Prykhodko wrote:
Hi.
How can I catch exceptions of sagarepository during saving saga? If saga's transaction is reverting I want to do some activities, but .Catch method seems not to be good for that...

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages