Hey,
I have the need for issue #77 and I'd like to take a stab at some
initial implementation. I like to reference Udi's idea of the
plumbing behind sagas:
http://www.udidahan.com/2009/04/20/saga-persistence-and-event-driven-architectures/
Axon would ideally provide:
1) a mechanism for persisting saga state
2) a mechanism for finding existing sagas based on events
3) a mechanism for ensuring that only one instance of a saga is
processing a triggering event
4) a mechanism to define timeout events to fire for a given saga
Udi takes advantage of C# generics which we can't do in Java (since
they're erased), so eventually we'll want to ensure all events are
handled properly at runtime.
1) State
Udi defines a SagaEntity interface which has a unique sagaId. Axon
would be responsible for setting the correct instance of a SagaEntity
on a saga.
2) Finding
I'm wondering if a Lookup class would have methods annotated with
@SagaFinder which would return an implementer of a SagaEntity;
something like "SagaEntity method(EventBase event)". An example would
be:
@SagaFinder
MoneyTransferSagaData findBy(FundsDeductedEvent event) {
// but what goes here?
return moneyTransferState;
}
What I'm unsure of is how sagas should be persisted. Should it be one
table per type of saga?
3) Locking
If there is one table per type of saga, then each row returned would
represent an instance of a saga; in which case we can use database
locking. Otherwise more thought is required.
4) Timeout
I feel like this feature can come in after saga persistence and
locking is managed; but it's definitely needed.