Hello everyone.
I have an app that created payment sequence based on postgres, via
- create sequence if not exists sequence_name;
- select nextval (‘sequence_name’)
I need this to have custom sequence logic, for example
organization 1
payment in store1 // sequence_number #1
payment in store2 // sequence_number #2
organization 2
payment in store1 // sequence_number #1
So I create sequence based on organization_id
I do this in PaymentAggregate, so this covers multithreading usage
The problem is when PaymentAggregate handles CreatePaymentCommand, in selects new sequence_number, but if later CommandHandler fails to successfully execute, Payment is not created, but sequence_number has already been choosen, and never will be used. And I have a hole in ordering payments.
How to get sequence_number in other way ? May be Axon provide some out-of-box implementation for this ?