ConflictResolution in Axon 3

41 views
Skip to first unread message

Jorg Heymans

unread,
Mar 16, 2018, 7:44:06 AM3/16/18
to Axon Framework Users
Hi,

I am trying to figure out how to best port a ConflictResolver to the new way of doing things in Axon 3. In Axon2, I was able to single out the particular event(s) that should trigger the conflict, and use them to construct a meaningful ConflictingUpdateException for the user. 

In Axon3, the mechanism to detect the conflict (Predicate) is separate from generating the exception (ContextAwareConflictExceptionSupplier). So basically when the exceptionsupplier kicks in, i have to reevaluate again the same predicates on the DomainEventMessage list to extract the conflicting ones. Intuitively, at least for me, the ExceptionSupplier should be supplied with the result of the predicate ie just the conflicting events if any.

Thoughts ?

Jorg


Allard Buijze

unread,
Mar 16, 2018, 8:05:57 AM3/16/18
to axonfr...@googlegroups.com
Hi Jorg,

the predicate you provide matches against a list of events. So if the predicate returns false, there is now way for Axon to know which event triggered the predicate. In fact, it may not even be a single event, but a certain occurrence of consecutive events.
The idea of the ConflictResolver is that you define a specific predicate for a specific (potential) conflict. If there are more than one potential conflicts, simply invoke the ConflictResolver multiple times. In that case, when the predicate "fails", you should know why and be able to provide a message directly.

Or am I missing something that you're trying to achieve?

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Allard Buijze
CTO

E: allard...@axoniq.io
T: +31 6 34 73 99 89

Jorg Heymans

unread,
Mar 16, 2018, 8:16:38 AM3/16/18
to Axon Framework Users
Hi Allard,

I understand that i could invoke the conflictresolver multiple times to cover multiple cases, but in order to construct the exception I need to have the list of events that triggered the conflict. I am actually extracting real data from these conflicting events, for example "User abc has already answered this question 5 minutes ago. The given answer was blabla". 

Jorg

Jorg Heymans

unread,
Mar 16, 2018, 8:28:36 AM3/16/18
to Axon Framework Users
Would this work ?

    conflictResolver.detectConflicts(t -> true, conflictDescription -> {
      for (DomainEventMessage<?> msg: Lists.reverse(conflictDescription.unexpectedEvents())) {
        if (/** detect conflicts here */) {
            return new ConcurrentAnswerException(msg);
          }
        }
      }
      return null;
    });


Still it seems funny to return null from the exceptionsupplier.

Allard Buijze

unread,
Mar 16, 2018, 9:51:37 AM3/16/18
to axonfr...@googlegroups.com
It could work, as no exception is raised when the Supplier returns null. But I agree, it's not beautiful.

One thing you could consider is to use a method that returns true, and use that as predicate. Then that predicate can be used in the detectConflicts() method (Wrapped in a Conflicts.eventMatching(..) to be able to match against a list of events), as well as inside the supplier to find the specific events that match that predicate.

Cheers,

Allard
Reply all
Reply to author
Forward
0 new messages